All jobs / AI engineer / LLM APIs
AI engineer interview question · 1–3 years
A service asks the model for an order as JSON and deserialises the reply straight into the order object. Now and then the parse fails, and once it created an order for a product that does not exist.
What is missing between the model’s reply and your order object?
The strongest answer
Validation. I use schema-constrained output where the provider has it, then check the parsed object in code — types, ranges, ids that must exist — and treat truncated or refused replies as an error path
Why it works
Exactly — a schema makes the shape reliable, not the content. Model output is untrusted input like any other, and a reply cut off at the output limit is not valid JSON.
What a good answer covers
- Model output is untrusted input.
- Constrain the shape with a schema.
- Validate values and ids in code.
- Truncation and refusal are error paths.
Answers that fall short
- Close, but not the strongest: A stricter prompt: say “reply only with valid JSON” and include an example of the exact shape
Instructions and an example raise the odds; they do not guarantee the shape, and they say nothing about whether the product exists. - Weak: A regex that pulls the JSON out of the text and patches any missing brackets before parsing
Repairing broken JSON by guesswork means you store values nobody produced. Reject and retry instead. - Red flag: Nothing much; wrap the parse in a try/catch and skip the replies that fail — it is rare
Silently skipping failures means lost orders nobody knows about. An interviewer hears “we ignore errors in the money path”.
Who gets asked this
More LLM APIs questions
- You turned on prompt caching for an assistant with a long system prompt and a dozen tools, but the provider’s…
- At peak your service starts getting HTTP 429 from the model provider. What should the client do?
- You switch the assistant to streaming. What changes for your backend beyond “the text appears sooner”?
- Traffic to the assistant grew by a tenth this month and the model bill doubled. How do you find out why, and…
- A nightly job classifies the day’s support tickets through the same synchronous endpoint and API key as the…
- What are your levers, in what order, and what do you promise?
- Your chat feature sends only the user’s newest message to the model API, and follow-up questions get confused…
- How do you choose which model to call for a new feature?