core Estimated learning time: 5 h

8.5 Structured output and tool schemas

Your model output parses reliably into your code.

Before:07. Natural Language ProcessingUnlocks:09. Agentic AI12. Frontier Topics

Structured output is what makes LLMs composable with code: JSON schemas, tool-calling contracts, Pydantic validation with retry loops — and a refusal path for unsupported cases, because declining is part of the contract. It sits here because everything agentic later depends on parseable output. The subtlety is that JSON mode is not enough: syntactically valid JSON can still violate the schema, and validation plus retry is what turns usually-parses into reliably-parses.

Work through these

  • JSON mode and schema-constrained output

    Asking for output in a fixed data format, and constraining generation so it conforms. The constrained version is what makes parsing dependable rather than probable.

  • Function/tool calling contracts

    Describing the functions a model may call, and the shape of their arguments. This contract is what lets a model act rather than only answer.

  • Validation with Pydantic and retry loops

    Validating the returned structure against a declared model, and asking again when it does not conform. The retry loop is a normal part of the design, not a workaround.

  • Refusing rather than guessing on unsupported cases

    A system that refuses a request it cannot satisfy is safer than one that produces something plausible. Designing for refusal is a deliberate choice made in advance.

Sign in to keep your progress.

Free resources

Links last checked 29 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.