Governance, Trust & Security

Trust but Verify: Schema Enforcement, Structured Outputs & Agent Evals

Prompted JSON — weakestJSON modeTool / function schemaValidation librariesGrammar-constrained — strongest

An agent's output is only as useful as the next step's ability to parse it. If a downstream system expects a decision, a number, or a category, and instead receives a paragraph of well-meaning but unstructured prose, the whole pipeline stalls. Getting a model to reliably produce machine-parseable output turns out to be its own layer of engineering, distinct from getting it to reason well in the first place — and it comes with a genuine ladder of guarantee strength worth knowing by name.

The ladder, weakest to strongest

At the weakest rung sits prompted JSON: simply asking the model, in plain language, to "respond only in JSON." This offers no real enforcement — the model can still drift into prose or produce syntactically broken JSON under pressure. One step up is JSON mode, where the provider constrains sampling to guarantee syntactically valid JSON, though it says nothing about whether the shape actually matches the schema you need.

The next rung, and the practical default for most production systems, is a tool or function-calling schema, where the output is forced into a declared tool's parameter schema and its types are checked. Close beside it sit validation libraries such as Instructor or Pydantic, which parse output into a typed model and automatically retry when validation fails, feeding the error back to the model so the next attempt can correct it. At the very top of the ladder sits grammar-constrained decoding, where the sampling process itself is restricted token by token to a defined grammar, making invalid output structurally impossible to produce in the first place — the strongest guarantee available, though the least commonly supported across providers today.

Structured output as a contract

It helps to think of a declared schema as a contract between the agent and whatever consumes its output — the same way a function signature is a contract between a piece of code and its caller. A trading system that outputs a structured decision with a fixed set of possible actions and a bounded confidence score can be acted on directly by downstream automation; a system that outputs a paragraph of reasoning, however sound, cannot be acted on without a human reading it first.

A second, related discipline: observability and evals

Structured output solves the problem of a single response being parseable. A second, related problem appears once an agent is autonomous enough to take multiple steps on its own: you need a way to see the trajectory it actually took, and a way to grade whether that trajectory was any good, at scale, without a human reviewing every run by hand. Observability is descriptive — it traces every LLM call, tool call, and state transition, and attaches latency, cost, and error status to each step, so the full trajectory can be reconstructed after the fact. Evals are evaluative — a trajectory eval asks whether the agent took a reasonable path, not merely whether it reached a correct final answer, because a correct answer reached via a bad path is a latent failure waiting to bite on the next, slightly different input.

A system with excellent tracing and no evals can tell you exactly how an agent arrived at a wrong answer, but never flags that the answer was wrong unless a human happens to notice. A system with strong evals and no tracing can flag that something regressed, but leaves you guessing why. Production agentic systems need both layers, running continuously — the same way a unit test suite gates a code change before it ships.

Questions to bring to your team

  • How do you currently validate AI output before it reaches a downstream system?
  • What would an ongoing eval process look like for your own use cases?

Also available in Čeština

← Keeping Humans in the Loop: Where Oversight Still Matters Retrieval-Augmented Generation as a Governed Tool Call — Not Magic →