Intermediate level · Module 5 of 9 · 11 guided hours
Structured Outputs and Validation
Production-quality structured outputs: Pydantic models with constraints, validating model JSON, retry with error feedback, provider structured-output features, and nested report schemas with references.
Learning objectives
- Define output models with Pydantic constraints
- Validate model outputs and retry with error feedback
- Design nested report schemas with references
Topics
- Pydantic models and field constraints
- Literal and enum values
- model_validate_json and ValidationError
- retry with error feedback
- provider structured-output features
- nested report schemas
Lessons
-
Lesson 1 Validating Model Outputs with Pydantic
Learners define Pydantic models with types and constraints and validate model JSON, reading the structured errors to see exactly what went wrong.
BaseModelField constraints (min_length, ge, le)Literalmodel_validate_jsonValidationError.errors()
-
Lesson 2 Retry with Error Feedback and Provider Features
Learners implement a validate-retry-fallback loop and compare it with providers' structured-output features that constrain responses to a schema.
retry with errorsfallbackprovider structured outputsschema-constrained generationstill validate
-
Lesson 3 Designing Report Schemas with References
Learners design the nested report schema for the level project: summary, findings with supporting references, open questions and confidence, with checks that tie every finding to evidence.
nested modelslist of findingsreference objects (document ID, passage)validatorsrendering to Markdown
Practical activity
Implement the project's validated output and report schemas with retry, fallback, source checking and rendering.
Expected outcomes
- Reliable, validated structured outputs
- Evidence-linked reports
Assessment
Schema and validation tests (70%) and rendered report review (30%).
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.