Free course · Lesson 4 of 5
Structured Outputs
In this lesson you will
- Read and design a JSON answer format
- Explain why outputs are validated
Free text is easy for people to read but hard for programs to check. A structured output puts each piece of information in a named field, usually as JSON, so the program can confirm that every answer cites a source and that sensitive topics are flagged for a person.
- Fields have types and allowed values: a category from a fixed list, a confidence between 0 and 1, at least one source.
- Every output is validated before anyone sees it. If it is invalid, the agent retries once with the error, then gives a safe fallback.
- Validation checks form, not truth: grounding and citation checks are still needed.
Valid: {"answer": "Second-term fees are due by 14 March.", "source_ids": ["fees-2026"], "confidence": 0.86, "needs_human": false} Invalid: {"answer": "Pay now", "source_ids": [], "confidence": 1.4}Problems: source_ids is empty; confidence is above 1; needs_human is missingResult: retry once with these problems listed; if still invalid, reply "I could not prepare a reliable answer - please contact the office."
Practice exercise
Design a JSON format for an assistant that answers market-price questions, including a field that says when a person must check the answer.
Key takeaways
- Structured outputs let programs check answers
- Invalid output is never shown to users
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.