CCAR-F - Prompt Engineering & Structured Output - Section 4.2

Apply few-shot prompting to improve output consistency and quality.

Few-shot examples are the most effective route to consistently formatted, actionable output when detailed instructions alone produce variance. They are how ambiguous-case handling is demonstrated, and they let the model generalise judgement to novel patterns instead of matching only the cases listed. Candidates should write two to four targeted examples that show the reasoning for choosing one action over a plausible alternative, and use them to cut hallucination in extraction from varied document structures.

few-shot examplesambiguous-case demonstrationgeneralisation to novel patternsoutput format demonstrationhallucination reduction in extraction

Practice question for this objective

Free samplePrompt Engineering & Structured Outputmedium

The Ledgerline team runs a document extraction service that asks the model to return supplier name, invoice number, invoice date and total as a JSON object, then validates that object against a JSON schema before it reaches the accounts payable system. Parse failures sat at 4 percent. An engineer adds three worked examples to the prompt, each pairing a short invoice with the exactly formatted JSON object it should produce, and parse failures fall to 0.6 percent across the next 20,000 documents. The architect has to record what the example set now guarantees about output structure. Which statement is correct?

  • AThe examples raise the probability of the demonstrated shape without bounding it, so schema validation remains the only stage in the pipeline where a malformed object is actually rejected before the downstream system sees it. Correct
  • BThe examples make the output shape deterministic for any document resembling the three worked cases, so schema validation is now redundant for that class of document and can be relaxed to a sampled check.
  • CThe examples constrain decoding to the demonstrated shape, so a malformed object can now arise only from an illegible source document rather than from the generation step itself.
  • DThe examples have no bearing on structure, and the fall in parse failures is attributable to the schema validation stage rejecting malformed objects and re-requesting them from the model.
Few-shot examples raise the likelihood of a demonstrated output format; only validation of the produced object enforces it. Worked examples condition the model towards the demonstrated structure, which reliably lowers malformed output, but the model still samples each response, so no example count converts a probability into a guarantee. The deterministic guarantee lives in the schema validation stage that inspects the object after generation and rejects it, which is why that stage must stay in place even after conformance improves sharply.

Why A is correct: Correct: few-shot demonstration shifts the output distribution towards the shown format, which is why the rate fell, while the deterministic guarantee still comes from validating the produced object and refusing it on failure.

Why B is wrong: Tempting because the measured improvement is large and consistent, but a demonstrated shape is still produced by sampling, so a lower failure rate is not a bound, and relaxing validation removes the one stage that actually rejects a malformed object.

Why C is wrong: Plausible because few-shot examples do strongly influence formatting, but examples are conditioning rather than a decoding constraint, so the generation step retains its own residual failure rate independently of document quality.

Why D is wrong: Tempting because validation genuinely does catch malformed output, but validation was already running before the change at a 4 percent failure rate, so it cannot explain an improvement that followed the addition of the examples.

See more CCAR-F practice questions, answers explained.

More in this domain

Back to all Prompt Engineering & Structured Output objectives, or the CCAR-F cert hub.

Examworthy is not affiliated with or endorsed by Anthropic. Original, blueprint-aligned practice material only.