Skip to main content

Lesson 7 · 11 min

Testing structured LLM outputs

Write deterministic tests for schema compliance, field accuracy, and edge-case coverage — and wire them into CI with accuracy thresholds.

What to test

Structured output tests fall into three categories:

| Category | What to check | Example assertion |

|---|---|---|

| Schema compliance | Does the output match the schema? | assert isinstance(result.score, float) |

| Field accuracy | Are the values correct for known inputs? | assert result.sentiment == "positive" for a happy review |

| Edge cases | Does it handle missing data, unusual input, refusals? | Empty string input returns a typed refusal, not an exception |