How do you test Python code that calls an LLM?
MediumConcept20 minMLESWEPro outline
The question
You are adding a feature that calls a language model API, parses its JSON output and writes a record to a database.
How do you structure the code and its tests so the suite is fast, deterministic and still catches real problems with the model's output?
What the interviewer is looking for
- Separates the model client behind an interface so it can be faked
- Unit tests parsing and business logic with recorded or hand-written responses
- Covers malformed output, timeouts, rate limits and retries
- Keeps a small, separate set of live or eval tests for real model behavior
- Thinks about flaky tests and how to keep CI deterministic
Your answer
Saved in this browser only. Nobody else sees it.
Why this question
Written by BlogLLM in the style of a publicly reported Cohere question type: Wiring LLM calls into Python code with tests.
Reported in: datainterview.com
Practice question written by BlogLLM based on publicly reported interview formats. Not an official Cohere question.