Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 4.8 — Playbook: Typed LLM Calls
LLM Engineering · Example 1 of 2

Recipe: parse_reply, text in, value or problems out

Extractor, type check, enum check in one function. Java uses the course's Json helper; real projects use Jackson.

The recipes of the whole phase in one place: parse a reply into a value or a list of problems, wrap it in one typed-call function that repairs and falls back, and count what happens. Copy these into any LLM feature.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write summarise_stats(stats, total) that returns first_try=A repaired=B fallback=C followed by repair rate: B of total as two lines, given a stats dictionary with those keys.

02

Write safe_label(parse_result, allowed) that takes (value, problems) and returns value['label'] if the value exists and its label is in allowed, otherwise "unknown".

Explain it without notes

01

Describe the typed-call recipe step by step.

02

Which counters would you put on a typed call, and what does each tell you?

03

How would you adapt this phase's recipes to a model that does not offer JSON mode?

04

Where does validation end and evaluation (Phase 9) begin?

Recipe: parse_reply, text in, value or problems out
Sign in to run this example in your browser.

Expected output

case 1: ok label=bug confidence=88
case 2: ok label=feature confidence=71
case 3: confidence: required field is missing
case 4: label: "refund" is not one of billing, bug, feature, unknown | confidence: expected integer, got string
case 5: no complete JSON object in the reply