Asked about Pydantic and type checkers in practice
Where should validation happen in an AI application?
An answer that works
At the boundaries: when data enters from users, from other services, and from the model. Validate once at the edge into typed objects, and let the inside of the system trust them.
Then they push further
Why treat model output like user input?
Because it can be anything. It can be malformed, out of range, or shaped by text an attacker put in a document. It needs the same checks as anything else that crosses a trust boundary.
Validation fails. What does your system do?
Retry once with the specific error passed back, then fail cleanly: store nothing, send the case to a review queue or return a clear error, and log it. Never store a guess.
What gets marked up
Marked up for treating model output as untrusted input and for a defined path when validation fails.
Reading an answer is not being able to give one. The section that teaches this is Pydantic and type checkers in practice, 5 hours of Typing & validation.
Learn this properly