Beginner level · Module 5: Structured AI Outputs · Lesson 3 of 3
Checking Outputs and Handling Failures
Learners run outputs through the validator, decide what happens when an output is invalid (retry, fallback or hand-over) and never pass unchecked output to people or programs.
In this lesson you will
- Validate agent outputs
- Define retry, fallback and hand-over rules
Key concepts
validationretry with feedbackfallback answerhand-overnever trust unchecked output
The lesson
Even with a schema, models sometimes return invalid output: missing fields, wrong values or broken JSON. Every output must be validated before it is used.
When validation fails, retry once with the error message included ('the field sources must contain at least one document'). If it fails again, use a safe fallback ('I could not prepare a reliable answer; please contact the admissions office') and log the case.
Never show or act on output that failed validation. This rule protects users from broken or invented answers.
Step by step
- Run 20 test questions and validate every output.
- Count the invalid outputs by error type.
- Add a retry-with-feedback rule and a fallback.
- Re-run and compare the counts.
Practice activity
Add validation, retry and fallback to the project assistant and measure the effect.
Expected result: No invalid outputs reach the user, with retry and fallback counts recorded.
Check your understanding
-
What should happen after a second invalid output?
Show answer
Use a safe fallback answer and log the case.
-
Why include the error message in a retry?
Show answer
It tells the model exactly what to fix.
Further learning
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.