Search, retrieve, and recover structure
The previous lessons established evaluation and operating constraints. This lesson uses them to choose among the official cookbook patterns. pattern: a reusable division of responsibility among retrieval, semantic judgment, deterministic policy, and visible product behavior is more useful than copying a demo threshold.
Patterns 1 and 2 are Noul self-consistency and Choice self-consistency: repeat frozen cases to observe probability and label movement, then test whether a review band stabilizes product actions. Pattern 3 is parallel questions: send independent judgments over shared state together, reducing repeated state and round trips while still paying for question tokens.
Self-consistency is a diagnostic pattern, not a request to vote away every uncertainty. Retain every run, distribution, changed irrelevant field, and resulting action. If repeated answers cross a policy boundary, either the question, threshold, or model version needs evaluation. Parallel batching should preserve identical question meanings; it does not allow one question to read another result. When a branch truly depends on an earlier answer, use a second request with newly retrieved state.
Pattern 4 is reranking: deterministic search retrieves candidates, one Noul per candidate judges relevance, and code sorts. Retrieval coverage is a separate metric because omitted evidence cannot be recovered. Pattern 5, line-by-line search, combines a Choice over line IDs with a Noul asking whether any answer exists, separating relative rank from absolute suitability. Pattern 6, structure recovery, asks Nouls about adjacent line breaks, stitches blocks in code, then uses Choices to label newly created blocks. It reconstructs rather than generates source text.
const candidates = bm25(query).slice(0, 30);
const state = {
query,
candidates: candidates.map(({ id, text }) => ({ id, text })),
};
const questions = Object.fromEntries(
candidates.map((candidate, index) => [
`relevant_${candidate.id}`,
{
type: "noul",
instructions: `Does \`candidates[${index}].text\` directly answer \`query\`? Judge only candidate ${candidate.id}.`,
},
]),
);
Trace this example from input to result
Customer choice
A support agent searches a versioned policy corpus.
Request or event
The query retrieves a bounded set of versioned policy passages.
Backend behavior
Jev judges relevance and contradiction while code preserves source text, provenance, and no-answer behavior.
Customer sees
The agent sees ranked evidence or an explicit no-answer result.
Diagnostic reasoning
Check retrieval coverage before judging the reranker; a perfect selector cannot recover an omitted passage.
Select tools, skills, entities, and evidence
Pattern 7 is function calling: a Choice selects among ordinary typed functions, additional bounded questions fill enum-like arguments, and code validates authorization. Open text arguments need extraction or generation. Pattern 8 is skill suggestion: rank a large skill list, independently ask whether any skill is needed, fetch details for top candidates, then allow rejection. This is staged because later state depends on the first result.
Pattern 9 is knowledge-graph entity alignment: a Score's ordered levels correspond to keep separate, curate, or merge, while companion Nouls identify field disagreements. Code still validates identifiers and performs the merge. Pattern 10 is RAG passage classification: separate Nouls judge relevance, usable evidence, contradiction, and embedded instructions; code builds evidence, conflict, and drop groups before generation.
Pattern 11 is citation checking: exact string matching first catches fabricated quotations, then a Choice labels surviving context as support, contradiction, or unrelated. Uncertain verdicts enter review. Pattern 12 is LLM guardrails: hazard Nouls and a harm Score inspect inputs and outputs, while policy maps the same signals to pass, review, block, or crisis handling. It does not prove adversarial robustness.
| Customer sees | Application does | Jev returns |
|---|---|---|
| A suggested tool that still asks permission | Filters allowed tools and validates arguments and identity | Relative tool choice and bounded risk judgments |
| A cited answer with review flags | Checks exact quotes, preserves sources, and routes uncertainty | Support, contradiction, or unrelated distribution |
A tool wins but cannot perform the request
choice=reset_password · account identity unverifiedThe Choice answered relative fit; it did not authorize execution. Deterministic capability and identity checks must filter or block the tool. Add a no-match path and review outcome, then test unsupported and unauthorized requests as separate synthetic fixtures.
Extract, classify, and build features
Pattern 13 is a structured data extraction (SDE) cascade: a cheaper generator extracts fields, Jev asks failure-signal Nouls about each field, and suspicious records escalate to a stronger reasoner or person. Jev verifies bounded claims rather than generating values. Pattern 14 is date extraction: Choices identify date kind and named components; code resolves relative dates, validates calendars, and compares values.
Pattern 15 is pre-parsed value extraction: regex or a parser intentionally over-finds email, phone, and amount candidates; Jev selects the intended source span and attributes; code copies and normalizes it. Candidate recall is the hard boundary. Pattern 16 is hierarchical classification: Choices traverse a pinned taxonomy. Greedy search keeps one path; beam search retains several and ranks with application math. The path score is not a calibrated leaf probability.
Pattern 17 is autoresearch feature discovery: a generator proposes narrow Noul and Score features, Jev evaluates them, and held-out outcomes determine which features survive in a classical model. This requires leakage control and stable labels. Pattern 18 is classification using confidence: a Choice predicts a fine class, then code returns a broader parent class or review when confidence is low. The threshold and hierarchy must be evaluated on the target distribution.
Feature discovery is especially vulnerable to overfitting because many proposed questions compete for the same limited outcomes. Keep a final untouched test set and record every search round. Hierarchical broadening has a different risk: a confident parent may be useful even when a leaf is uncertain, but only if the taxonomy version and parent mapping are deterministic. Never describe the cookbook path score as the probability that the leaf is correct.
function normalizeSelectedAmount(candidates: Candidate[], selectedId: string) {
const candidate = candidates.find((item) => item.id === selectedId);
if (!candidate) throw new Error("Selected candidate is absent");
return parseCurrency(candidate.exactText); // code copies and parses source
}
Dig deeperCompose patterns without collapsing boundaries+
A support assistant might retrieve passages, classify them for evidence and contradiction, verify citations, select a tool, and gate its action. Keep every intermediate artifact and question version. Do not turn the composition into one broad "is this response good?" judgment: that loses the ability to locate missing retrieval, unsupported citation, unsafe tool choice, or policy failure. Combine independent questions in one request only when they share state and do not depend on one another's answers.
Choose a pattern from the failure you can tolerate
Begin with what the customer sees. If they need a source value, select and copy rather than generate. If they need ranked evidence, retrieve broadly and rerank. If they need a reversible route, use Choice plus no-match and review. If they need an exact date or amount, extract bounded components and let code calculate. If a generator already exists, use Jev as a narrow verifier and escalate suspicious cases.
Across all eighteen patterns, preserve deterministic invariants: candidate coverage, permissions, arithmetic, source fidelity, idempotency, and current state. Evaluate answer quality and downstream action separately. Treat cookbook thresholds and measurements as worked examples, and label your own fixtures synthetic.
A pattern review should finish with a deletion test: what breaks if the Jev judgment is unavailable? If the entire product loses its source record or permission check, the boundary is too deep. A sound design preserves customer data, provenance, and safe review while losing only the semantic convenience. Also ask whether a simpler parser, lookup, or rule already solves the task. Jev earns its place where meaning is genuinely needed and measured.
Map a workflow to patterns
Your answers stay in this browser. Write enough that another engineer could continue the investigation.
Check your understanding
Select among all eighteen cookbook patterns by the product behavior and failure boundary, then keep retrieval, semantic judgment, policy, and execution independently testable.