Typing & validation interview questions

5 questions across 2 sections, in the order you would learn them. Every answer here is one that works — but an answer you have read is not an answer you can give, so use Test yourself and say it out loud first.

Validating at the boundary

Read the section that teaches this

If this comes up in an interview

Where should validation happen?

At every boundary where data enters from somewhere you do not control, and only there. Past that point everything downstream can assume the shape is correct, which keeps the checks in one place instead of scattered and drifting.

Why is model output untrusted input?

It is generated rather than guaranteed. It is usually the shape you asked for and sometimes is not, and a schema only guarantees structure, never that the values are real. Treat it like a form submission from a stranger.

What is the benefit of generating a JSON schema from your validation model?

The contract you send to the API and the check you run on the response come from one declaration, so they cannot drift apart. Change the shape once and both follow.

Pydantic and type checkers in practice

Read the section that teaches this

If this comes up in an interview

Where should validation happen in an AI application?

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.

What is a discriminated union and when would you use one?

A union of shapes with a tag field that says which shape an object is. It suits outputs that can be one of several actions, and gives precise errors because the validator knows which shape to check.

These are the questions for one topic. The whole question bank covers every topic on the site.