Sub topic 13
Live smoke tests, and why they are not evals
This chapter assumes you have read the earlier chapters of this tutorial. You should have a narrow client seam (the ChatClient protocol), a scripted fake, and recorded responses that you replay offline. You should also be comfortable with pytest markers and environment variables.
Fakes and recordings test your code. Neither one tests the real API. A fake only returns what you wrote, and a recording only returns what the API said on the day you recorded it. This chapter covers the last layer: a few tests that call the real service. It also explains why those tests are a different thing from evals.
What a live smoke test is for
A live smoke test answers one question: "Does my code still work with the real API right now?" It checks the contract between your code and the provider. It does not check whether the model is smart.
Things a smoke test can catch:
- An expired or misconfigured API key.
- A model name that was retired or renamed.
- An SDK upgrade that changed a method signature or response shape.
- A change in the reply format that breaks your parser. One example is the model starting to wrap JSON in a Markdown code fence.
- A changed rate limit, timeout, or error type.
- Drift that your recordings hide. A recording keeps replaying the old reply after the real API has moved on.
Things a smoke test should not try to catch:
- Whether answers are accurate across many inputs.
- Whether a prompt change made output better or worse.
- Whether one model beats another.
Those are questions for evals, covered below.
Where smoke tests sit
The test suite has three layers. The lower layers run on every commit. The live layer runs rarely and on purpose.
The fake and replay tests give you fast, deterministic feedback. The smoke tests give you a periodic reality check. Because they are slow, they never block the inner development loop.
Keep live tests out of the default run
A live test must be opt-in. If pytest with no arguments calls a paid API, someone will eventually run it on a plane, in a CI job with no key, or in a loop. Use a pytest marker and skip marked tests unless an environment variable is set.
# conftest.py
import os
import pytest
def pytest_configure(config):
config.addinivalue_line(
"markers", "live: calls the real model API; skipped unless RUN_LIVE=1"
)
def pytest_collection_modifyitems(config, items):
if os.environ.get("RUN_LIVE") == "1":
return
skip_live = pytest.mark.skip(reason="set RUN_LIVE=1 to run live smoke tests")
for item in items:
if "live" in item.keywords:
item.add_marker(skip_live)With this file, the default run reports live tests as skipped. The skip count in the output reminds you that they exist.
Write the smoke test
The real client is a thin adapter that satisfies the same ChatClient protocol your fakes satisfy. This example uses the Anthropic Python SDK. Any SDK works the same way, because only the adapter knows about it.
# tests/test_live_smoke.py
import os
import anthropic
import pytest
from invoices import extract_total # the function from the earlier chapters
class AnthropicChatClient:
"""Adapter from the Anthropic SDK to the one-method ChatClient protocol."""
def __init__(self, model: str, timeout: float = 30.0):
# max_retries=0: a smoke test should surface a failure, not hide it.
self._client = anthropic.Anthropic(timeout=timeout, max_retries=0)
self._model = model
def complete(self, prompt: str) -> str:
response = self._client.messages.create(
model=self._model,
max_tokens=200,
messages=[{"role": "user", "content": prompt}],
)
return response.content[0].text
@pytest.mark.live
def test_extract_total_contract():
client = AnthropicChatClient(model=os.environ["SMOKE_MODEL"])
total = extract_total(client, "Invoice 17\nTotal: $42.50")
assert isinstance(total, float)
assert total > 0Run it explicitly:
RUN_LIVE=1 SMOKE_MODEL=your-model-name pytest -m liveThe key comes from ANTHROPIC_API_KEY in the environment. It is never written in the test file.
Design rules for the assertions
The test asserts on shape, not on exact wording. It checks that the result is a float and that it is positive. The invoice here is trivial, so asserting total == 42.5 would also be reasonable. For anything less trivial, an exact-text assertion makes the test flaky, because the model may phrase things differently on each run.
Follow these rules:
- Assert on structure: the JSON parses, the required keys exist, the types are right.
- Assert on properties that any correct answer has, such as "non-empty", "within the allowed set of labels", or "under the length limit".
- Do not assert on prose. If your code returns free text, check only that it is a non-empty string.
- Run each smoke test once. If a test needs ten samples to pass, it is an eval, not a smoke test.
A failure from json.JSONDecodeError here is a useful finding. It tells you the live reply format no longer matches what your fakes and recordings assume. The fix is to update your parser and your recordings, not to loosen the smoke test.
Control cost and time
Smoke tests cost real money and real seconds, so cap both.
- Keep the count small. Five to ten tests that each touch one integration point are enough. One test per distinct code path that talks to the API: plain completion, structured output, streaming, tool call.
- Use the cheapest model that exercises the same API surface. If production uses a large model, a smoke test usually can use a small one, unless the thing you want to check is that specific model name.
- Set
max_tokenslow and keep prompts short. - Set a client timeout, as in the adapter above, so a hung connection fails in seconds.
- Disable SDK retries in the smoke client so that a transient failure is visible. Your own retry logic is already covered by fake-based tests.
When to run them
Run smoke tests on a schedule and at specific events, not on every push.
| Trigger | Why |
|---|---|
| Nightly or weekly scheduled job | Catches provider-side drift even when your code did not change |
| Before a release | Confirms the deploy candidate works with the real service |
| After upgrading the SDK | SDK changes are a common source of silent breakage |
| After re-recording cassettes | Confirms that the new recordings still describe real behavior |
| After changing a model name | Confirms that the new name exists and replies in the same format |
A scheduled failure should alert someone, but it should not be treated as a broken build. Provider outages and rate limits also cause failures. Before blaming your code, read the error: an authentication or "model not found" error is a configuration issue, while a parse error points at format drift.
Handling flakiness honestly
Even a well-built smoke test can fail on a bad day, because the network and the model are both outside your control. Two approaches are reasonable:
- Rerun once on failure, and report the failure only if the second run also fails. A pytest plugin such as
pytest-rerunfailuresprovides this, and CI systems can do it at the job level. - Treat a failure as a signal to investigate, not a verdict. A single failure is a reason to look. Three nights in a row is a reason to change code.
Do not add large retry loops or loosen assertions until the test never fails. A smoke test that cannot fail tells you nothing.
Why smoke tests are not evals
Both kinds of test call a real model, so they look alike. They differ in purpose, in method, and in what a failure means.
| Row | Live smoke test | Eval |
|---|---|---|
| Question answered | Does the integration work? | How good are the answers? |
| Inputs | A handful of fixed, simple cases | A larger set of representative cases |
| Result | Pass or fail | A score, such as accuracy or a pass rate |
| Assertions | Structure and basic properties | Correctness against expected answers, or a grader's judgment |
| Typical failure | Auth error, renamed model, parse failure | Score drops after a prompt or model change |
| Decision it informs | Is the code safe to ship? | Is this prompt or model good enough? |
An eval looks at aggregates. It runs the model over many cases and reports a rate, and it tolerates some individual wrong answers. A minimal version of the idea:
import json
def run_eval(client, cases):
"""cases is a list of (invoice_text, expected_total) pairs."""
correct = 0
for text, expected in cases:
try:
if extract_total(client, text) == expected:
correct += 1
except (json.JSONDecodeError, KeyError, TypeError, ValueError):
pass # a parse failure counts as a wrong answer
return correct / len(cases)This function returns a number, such as 0.85, and you compare that number across prompt versions. A real eval setup adds a larger dataset, versioned results, and often a grader for open-ended answers. Eval design is a separate topic from this chapter.
Keep the two apart for these reasons:
- Mixing them makes tests ambiguous. If a "test" fails at 80% accuracy, nobody can say whether the code is broken or the model is just imperfect.
- Evals are too slow and expensive for the pass-or-fail role. Smoke tests would be too thin to guide prompt changes.
- A smoke test with a statistical threshold ("must succeed 9 times out of 10") is flaky by design. Put such thresholds in an eval report, where a dip is information rather than a red build.
Putting the whole strategy together
A reasonable end state for a project that uses an LLM:
- Most tests use scripted fakes. They cover your parsing, validation, retry, and error handling, and they run in milliseconds.
- A smaller group replays recordings. They cover SDK and HTTP-level behavior and realistic reply shapes.
- Five to ten live smoke tests check the real contract on a schedule and before releases.
- A separate eval suite, run when prompts or models change, measures answer quality.
When a smoke test fails because the real API changed, the repair order is: fix the code, update the fakes so they match the new behavior, re-record the affected recordings, and run the smoke tests again.
Exercise
Your nightly smoke test fails with a JSONDecodeError because the model now wraps its JSON reply in a Markdown code fence. Your fake-based tests and your replay tests all still pass. Why do they still pass, and what should you change?
Show answer
The fakes return exactly the replies you scripted, and the recordings replay the old reply format, so neither one can see that the real API changed. The smoke test is the layer that caught the drift. Fix the parser to strip the fence (or change the prompt or API settings so the model returns bare JSON). Then add a scripted-fake test with a fenced reply so the new behavior is covered offline, re-record the affected recordings, and rerun the smoke test to confirm.
Exercise
A teammate proposes a smoke test that sends 50 invoices to the real model and fails the build if fewer than 90% of the totals are correct. Is this a smoke test? What would you do instead?
Show answer
It is an eval. It measures answer quality across many cases and uses a statistical threshold, which makes it slow, costly, and flaky as a pass-or-fail check. Keep the smoke test to one or a few simple invoices that check structure, such as a parsed float. Move the 50-case run into a separate eval job that reports the accuracy as a score you track over time and compare across prompt or model changes.