Format failures are bugs disguised as quality issues
If your prompt asks for JSON and the model returns markdown-wrapped JSON, your downstream pipeline crashes. That is not a quality failure — it is a format compliance failure, and it deserves its own metric.
What format validation catches
- JSON parses correctly, with the expected keys and types.
- Code blocks are well-formed and the listed language matches the content.
- Citations follow the required pattern (numbered, bracketed, with sources).
- Lists have the right cardinality (e.g. exactly 5 bullet points).
- Output stays within length constraints (max 100 words).
- Required tokens appear ("FINAL ANSWER:", "Step 1:", etc.).
Three levels of strictness
- Regex match — pattern check. Fast, brittle.
- Schema validation — Pydantic / JSON Schema / Zod. Catches type errors and missing fields.
- Semantic validation — schema passed, but does the content satisfy invariants? (e.g. citation IDs reference real sources)
Principle: Format compliance is a separate axis from quality. Track them independently. A model that produces beautiful prose but breaks your JSON schema 10% of the time is broken.
Modern providers offer structured-output modes
OpenAI's response_format=json_schema, Anthropic's tool-use system, Google's controlled generation. They guarantee schema-valid output. If your task allows it, use them — format-failure rate drops to near zero. Then your eval focuses on semantic correctness.