Let’s Get Certified
Module 09 / 12 · Prompt engineering and structured output

From review criteria to a typed result

Write a decision rubric, teach its boundaries, and capture a result with a schema.

Make a reviewer’s decisions reproducible

A review bot reports “the comment may be stale” on almost every pull request. The team dismisses most of these comments. A more forceful instruction to be careful leaves the decision boundary undefined.

4.1 · Define what earns a finding

Report a stale contract only if an identifiable input produces behavior that contradicts a documented promise. Require a location, triggering input, actual effect, and repair. Skip wording preferences. Reserve high severity for a demonstrated data loss or incorrect irreversible outcome. Use medium for a recoverable wrong result with a reproducible trigger. If a category floods reviewers, pause that category, examine dismissals, and test a revised rubric before re-enabling it.

Repair a noisy review category

A reviewer flags 20 allegedly stale comments. Humans confirm four actual contradictions and dismiss 16 wording preferences. A separate category finds three genuine data-loss errors with no dismissed findings. The developer asks for a global “be more conservative” instruction. What should change first?

Calculate precision before rewriting the rubric

Precision for the comment category is 4/20, or 20%. That figure gives no estimate of the contradictions the reviewer missed. Preserve the valuable second category. Temporarily suppress automatic publication of the noisy category while running a revised rubric on labeled examples.

Require an identifiable comment promise, an input, and a conflicting observable result. A comment promising an empty list while the function returns null for that input qualifies. A synonym that preserves behavior does not. Define severity by consequence and reachability. On a held-out set, inspect both true findings retained and false findings removed before restoring automatic comments.

Video background · freeCodeCamp at 9:39:07 · False positives from vague instructions

4.2 · Teach the boundary with examples

Use a few varied examples with an expected decision and a short justification. A comment promising an empty list when the code returns null earns a finding. A local alias that preserves the promised output earns none. A new branch exercised only by an existing fixture also earns none if that fixture asserts the behavior. Demonstrate one full record with location, impact, severity, and fix. Test on unseen changes to see whether the reviewer learned the distinction.

For document extraction, pair a measurement embedded in prose with another in a table or footnote. Show how approximate values retain their qualifier and how an absent value is returned. Include a case in which a bibliography mentions a quantity that does not describe the document’s subject.

Teach a boundary with examples that disagree on one fact

An extractor often reports the first date it sees as the inspection date. You need examples that also teach the desired record format. Design a pair for “issued 3 May, inspected 1 May” and “issued 3 May, inspection date unavailable.” Then test whether the rule transfers to a new layout.

Try the examples on a new layout

In the first example the output contains the inspection date of 1 May, the inspection phrase as evidence and a present status. In the second it contains a null inspection date and a missing status. Explain briefly that the issue date is evidence of a different event. Both outputs use the same fields so the learner can see which value changes with the evidence.

Hold out a form with the inspection date in a footnote and an unrelated bibliography date at the top. A correct extractor cites the footnote. If it succeeds only when the inspection label appears first, add an example varying position while preserving the decision rule, then test on another unseen form.

Official reference · Official CCAR-F exam guide, sample questions and practice exercises

4.3 · Constrain shape and represent missing information

Define a named tool with an input_schema, enable supported strict tool use, and force that tool when a downstream consumer requires its record. Read the arguments from the matching tool_use block. If several extraction tools are permissible and one must run, select any. Separate required keys from values that may be null. An enum can include “unclear” for insufficient evidence and “other” with a detail field for a known unlisted category.

{"type":"object","properties":{
  "currency":{"type":["string","null"]},
  "amount_minor":{"type":["integer","null"]}
},"required":["currency","amount_minor"],"additionalProperties":false}

Give normalization rules for currencies, units, and dates. A schema can enforce an integer and a valid currency code while still assigning the amount to the wrong invoice. Validate business meaning and evidence after parsing.

Validate the meaning of a schema-compliant receipt

A receipt prints a total of EUR 18.50, gives no settlement date and describes an unfamiliar fee as a “canal levy.” The consumer requires keys for amount, currency, date, fee type and fee detail. How can a record pass the schema and still send the wrong value to accounting?

Separate extraction and acceptance

Use an integer minor-unit amount of 1850, currency EUR, a present date key with a nullable value, and an extensible fee category such as other plus the source description. Set a rule for decimal normalization. Use unclear when the evidence is ambiguous, preserving the distinction from a clearly stated but unfamiliar category.

Force the named extraction tool when that specific record is required and read its structured arguments. A schema can also accept 185 as an integer or an issue date copied into settlement date. Compare with the printed total and event label in a separate validation step. Check exception cases before forwarding a valid-looking object to accounting.

Video background · freeCodeCamp at 9:17:40 · Schema-constrained extraction with a tool

Further reading · Structured outputs · Official CCAR-F exam guide, sample questions and practice exercises

Knowledge check

From review criteria to a typed result quiz

Answer 9 questions. Check each answer for an explanation.