Command Palette

Search for a command to run...

Hectal
Phase 11: Observability and Operations
LLM Engineering · Exercise 5 of 5 Previous
Advanced

Record the failure, then re-raise

ProviderError and a fake model are given. Write observed_call(model, prompt, records) that calls model.complete(prompt), which returns a dict with tokens_in, tokens_out and latency_ms, or raises ProviderError.

Append exactly one record to records for every call: {"status": "ok" or "error", "tokens_in": ..., "tokens_out": ..., "latency_ms": ...}. On success return the reply. On a ProviderError the record has the status error, tokens_out 0, tokens_in equal to (len(prompt) + 3) // 4 and latency_ms taken from the exception's latency_ms attribute, and the error must be raised again.

What Check tests

  1. A successful call returns the reply and records it
  2. A failed call is still recorded
  3. The error is raised again to the caller
  4. Exactly one record per call, in order

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.