Page 6 of 8~112 min topic

Talk to an LLM from code

Instrument the CLI LLM summarizer

Page 6 adds signals that distinguish bad input from component failure in the command-line LLM summarizer.

~14 min this pageTesting and observability

1Learn the idea

Read

Emit stage signals

Instrument the command-line LLM summarizer so a run records enough structure to debug offline: counts, latency if relevant, pass/fail of contract-test pass rate, latency, retry count, output length, and a stable stage name. Redact secrets and raw credentials from every event.

Read

Emit and assert

const event={ok:true,latency_ms:84,retries:0,model:'demo',input_chars:42};
console.log(JSON.stringify(event)); if(event.latency_ms>1000) process.exitCode=1;

Expected evidence: stage evidence for observability. Prefer JSON or structured text you can grep in CI over prose logs for llm-api-hello.

Read

Lock signals with a regression test

Turn one historical failure—especially missing choices array treated as empty success—into a test that fails if the signal disappears for the CLI LLM summarizer. Observability without a failing test is optional decoration; observability with a test is part of the llm-api-hello artifact.

Read

Lab notebook: signal schema

Draft a three-field event for the CLI LLM summarizer: stage, ok, and one domain field derived from contract-test pass rate, latency, retry count, output length. Add fixture_id or docs_version when content can change. Explicitly list fields that must never appear (tokens, passwords, raw prompts) because printing API_KEY or full prompts into logs is in scope for this lab.

Wire one assertion that fails if the CLI LLM summarizer event is missing after a run. Observability that cannot fail a test will not survive contact with a busy llm-api-hello repository.

Read

Worked judgment

Imagine a teammate opens only your event stream after a bad deploy. Could they tell whether system+user job object for an embeddings definition sentence was wrong, whether missing choices array treated as empty success, or retries on 400 returned, or whether printing API_KEY or full prompts into logs slipped through? If not, rename fields until those three stories are distinguishable.

Read

Why this stage matters for the CLI LLM summarizer

At the testing and observability stage for llm-api-hello, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about system+user job object for an embeddings definition sentence that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: offline fake transport producing a fixed summary.

For this page specifically, success looks like a structured event schema locked by a test while still centering the user decision to turn one user passage into a bounded one-sentence summary via an HTTP-shaped client. If you cannot point to a file, command, or assertion that proves that for the CLI LLM summarizer, stay on this page instead of advancing.

API: chat completions · Glossary: API key

Previous · Next

Go deeper

Before you start

Why this matters

Write the single log line or metric event that would tell you whether a bad result came from input vs implementation for the CLI LLM summarizer. If your line could not tell them apart, redesign it before coding.

In the wild

See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Can input faults be distinguished from component faults in the event?
2. Are secrets redacted from logs?
3. Is there a test that fails if the signal vanishes?
4. Does the event still reference the decision: turn one user passage into a bounded one-sentence summary via an HTTP-shaped client?

All responses are required.