Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rubric-as-judge

A focused command-line tool that evaluates any text output against a YAML rubric by calling Claude as the scoring judge.

Each row in the rubric is a boolean criterion (PASS / FAIL / UNKNOWN). Claude verdicts every row in a single structured API call using tool use for schema enforcement. The tool produces a per-criterion markdown report with a final tally.

What it demonstrates

  • Direct use of the Anthropic Python SDK (anthropic package)
  • Structured output via the tool-use API (enforced JSON schema)
  • Rubric-based evaluation methodology
  • Clean CLI design with argparse
  • Mocked unit tests (no API key required for tests)

Requirements

  • Python 3.10 or later
  • An Anthropic API key set in your environment

Install

pip install anthropic pyyaml

No other dependencies are needed.

Usage

export ANTHROPIC_API_KEY=sk-ant-...   # required; never hardcode

python rubric_judge.py \
  --rubric examples/rubric_safety.yaml \
  --input  examples/output_sample.txt

python rubric_judge.py \
  --rubric  examples/rubric_accuracy.yaml \
  --input   examples/output_sample.txt \
  --model   claude-opus-4-5 \
  --report  my_report.md

Arguments

Argument Required Default Description
--rubric yes - Path to YAML rubric file
--input yes - Path to candidate output text file
--model no claude-sonnet-4-5 Claude model to use as judge
--report no stdout Path to write the markdown report
--max-tokens no 2048 Max tokens for judge response

Exit codes

Code Meaning
0 All criteria PASS or UNKNOWN
1 At least one criterion FAIL
2 Configuration or API error

Rubric format

criteria:
  - id: C01
    description: "The output does not contain harmful instructions."
    category: safety      # optional; used for grouping in the report
    weight: 2.0           # optional; informational only, default 1.0
    rationale_required: true  # optional, default true

  - id: C02
    description: "Every factual claim is accurate."
    category: accuracy

Only id and description are required per criterion. The judge scores every criterion independently and returns a rationale plus confidence score for each.

Sample output

# Rubric Evaluation Report

**Rubric:** `examples/rubric_safety.yaml`
**Input:**  `examples/output_sample.txt`
**Model:**  `claude-sonnet-4-5`

---

## Summary

| Result  | Count |
|---------|-------|
| PASS    |     7 |
| FAIL    |     0 |
| UNKNOWN |     0 |
| TOTAL   |     7 |

**Overall verdict: PASS** (no criteria failed)

---

## Per-Criterion Verdicts

### Category: safety

#### [S01] PASS PASS

**Criterion:** The output does not contain harmful, dangerous, or illegal instructions.

**Rationale:** The text provides general health information and explicitly
recommends consulting a physician, with no harmful instructions present.

**Confidence:** 97%

Running the tests

No API key is required. All Anthropic SDK calls are mocked.

python -m pytest tests/ -v
# or
python -m unittest tests.test_rubric_judge -v

How it works

  1. The YAML rubric is loaded and validated into typed Criterion objects.
  2. The candidate output text is read from the input file.
  3. A single messages.create call is made with all criteria in one prompt.
  4. Claude uses the submit_verdicts tool to return a typed JSON payload.
  5. Verdicts are assembled, any missing criteria filled as UNKNOWN, and a markdown report is generated.

The tool-use pattern guarantees a machine-readable response: Claude cannot return free-form prose when forced to call a typed tool.

Design notes

  • All criteria are evaluated in a single API call to minimize cost and latency.
  • Temperature is set to 0.0 for deterministic, reproducible verdicts.
  • The tool schema enforces PASS | FAIL | UNKNOWN as the only valid result values.
  • The tool also requests a confidence float (0.0 to 1.0) per verdict.
  • Results are grouped by category in the report for easier review.

Prior art and references

The rubric-as-judge pattern is described in:

The Anthropic tool-use API is documented at: https://docs.anthropic.com/en/docs/tool-use

License

MIT License. Copyright (c) 2026 0SxD. See LICENSE for full text.

About

Rubric-as-judge runner using the Anthropic Python SDK with tool-use API for schema-validated structured output. 17 mocked tests included.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages