| Contract | Function | Best for |
|---|---|---|
sample | grade(sample, item[, ctx]) | Per-sample exact match, F1, numeric tolerance, regex, custom rubric checks. |
batch | grade_batch(samples[, ctx]) | Aggregate scoring, macro metrics, task-level judges, or sample updates after seeing the whole batch. |
model_backed | grade or grade_batch with ctx model helpers | LLM-as-judge and embedding/similarity scoring through MKA1. |
ctx.responses_create and ctx.embeddings_create for model-backed scoring.
Grader declaration
Use inline source for short graders:| Field | Description |
|---|---|
type | Must be python. |
contract | sample, batch, or model_backed. Defaults to sample. |
execution | Optional override: per_sample or aggregate. Defaults from contract. |
model_access | mka1 enables ctx.responses_create and ctx.embeddings_create. Defaults to mka1 for model_backed, otherwise none. |
metric_id | Score key used when the grader returns a single float. Defaults to score. |
source | Inline Python source. |
file_id | Uploaded Python file ID with purpose=evals. |
timeout_seconds | Sandbox execution timeout. Range is 1 to 600. Defaults to 120. |
max_model_calls | Maximum bridge calls from one grader execution. Range is 0 to 500. Defaults to 64. |
source or file_id.
Sample contract
Sample graders define:ctx:
sample describes the model output:
item contains the dataset row plus convenience fields:
Return a single score
Return a finite float when the task has one metric. MKA1 stores it undermetric_id.
metric_id is omitted, the score key is score.
Return multiple scores
Return a dict with ascores object when the task has multiple metrics.
scores.
The optional judge object is preserved on the sample for debugging and dashboards.
Invalid results
The following results become invalid and receive a zero score:- Exceptions.
- Non-finite floats such as
NaNorInfinity. - Boolean returns.
- Strings or other non-dict, non-number returns.
- Dicts without any finite numeric score.
judge payload includes the raw invalid payload and error details.
Batch contract
Batch graders define:| Field | Description |
|---|---|
sample_id | Required. The sample to update. |
scores | Optional numeric score keys to merge into the sample. |
judge | Optional object to replace sample judge details. Use null to clear. |
extracted_output | Optional string or null to replace the sample extracted output. |
metrics, unexpected batch metric IDs are dropped from final aggregates.
This protects dashboards from accidental metric drift.
Model-backed graders
Usecontract: "model_backed" when Python needs model or embedding calls.
The Python code asks for a tool call.
Gateway performs the call with the run’s authenticated context and returns the result to the sandbox.
judge_model and embedding_model when the grader uses model="auto":
model="auto" or omits model, MKA1 uses the run’s judge_model or embedding_model.
LLM-as-judge
ctx.responses_create accepts the same request shape as the MKA1 Responses API, except the eval system forces stream=false, store=true, and background=false.
Judge responses are stored and can be audited like normal Responses traffic.
Embedding similarity
ctx.embeddings_create routes through the MKA1 Embeddings API.
Usage is logged under the run’s authenticated context.
Python preprocessors
Preprocessors are not graders, but they use the same sandbox execution model and file loading rules. They run before prompt rendering. Row preprocessor:Common scoring recipes
Exact match
Case-insensitive exact match
Numeric tolerance
Token F1
Macro F1 with grade_batch
Debugging graders
Use sample details first:curl
| Field | What to check |
|---|---|
prompt | The rendered prompt after preprocessing and few-shot examples. |
target | The rendered target string. |
output_text | Raw model output after stop-sequence handling. |
extracted_output | Output after extraction. |
scores | Numeric values that affected aggregate metrics. |
judge | Grader-returned details plus raw execution payload when available. |
error | Candidate generation, extraction, preprocessing, or sandbox failure details. |
| Symptom | Fix |
|---|---|
Score is always 0 | Check that the grader returns a float or a dict with finite numeric scores. |
ctx.responses_create fails | Set contract: "model_backed" and model_access: "mka1", then provide a judge_model on the run or an explicit model in Python. |
ctx.embeddings_create fails | Set an embedding_model on the run or pass an explicit embedding model in Python. |
| Prompt fields are blank | Verify the dataset row field names and preprocessor output. |
| Batch metrics are missing | Declare the metric IDs in metrics, or omit metrics for aggregate tasks that should accept every returned metric. |
| Grader times out | Increase timeout_seconds, reduce model bridge calls, or move expensive aggregate work into smaller tasks. |
Security model
Python graders and preprocessors execute in the sandbox service. They are intended for eval logic, not for arbitrary application workflows. Keep these rules in mind:- Do not put secrets in grader source, dataset rows, or metadata.
- Do not expect raw network credentials inside Python.
- Use
ctx.responses_createandctx.embeddings_createfor model calls. - Keep uploaded Python files scoped to the team that owns the suite.
- Prefer uploaded grader files for reusable logic so suite versions clearly track their dependencies.
response_ids and grader judge payloads, so you can audit how scores were produced.