Design structured input and output contracts
Reading estimate uses 200 words per minute and excludes exercises, self-review and optional book descriptions. Earlier lesson checks are kept; revisit the expanded text if you completed the short edition.
Specify versioned request and candidate-output contracts with field ownership, unknown-value rules and separate structural, semantic and source-fidelity checks.
Components cooperate through contracts: defined meanings for the information they send and receive. A structured object can make errors easier to detect, but tidy JSON does not prove that its claims are true or authorised. This lesson specifies the workshop desk's validated request and candidate-summary objects, including required fields, unknown values, source links and version rules. The work is a design exercise with fictional records. It does not connect a parser, model or database, and every proposed validation rule remains something an implementation would need to enforce and test.
In this lesson · 12 sections
- Name the interface and the claim it carries
- Define the request fields and ownership
- Define the candidate-summary fields
- Choose types and value ranges deliberately
- Distinguish missing, empty and unknown values
- Specify treatment of unexpected fields
- Define structural and semantic validation separately
- Make error objects useful to the sender
- Version contracts without silently breaking consumers
- Build a contract test pack with expected failures
- Trace a candidate through validation and review
- Deliver the interface contracts and validation matrix
1. Name the interface and the claim it carries
Choose two interfaces from the component map. The validator sends a draft request to the language worker; the worker returns a candidate summary to the review path. These messages serve different purposes and should not share one vague object called result. The request establishes the authorised input basis for a narrow language task. The response supplies a candidate artefact and its unresolved items, not permission to publish.
Write a contract purpose sentence for each. The request contract tells the worker which approved source version and verified values it may use. The response contract lets the next component inspect what was produced and trace important claims. This purpose guides field selection. Adding every available record to a structured object does not improve its contract if receivers cannot tell which values they may rely on. A useful interface reduces hidden assumptions by making the scope and meaning of each field explicit enough that a different component or maintainer can process it correctly.
2. Define the request fields and ownership
The fictional request includes contract version, request identifier, source packet identifier and version, task type, approved facts, verified numeric fields and unresolved input issues. Identify who supplies each field. The state owner supplies the current request and source basis; the deterministic calculation component supplies any verified difference; the operator supplies the authorised task scope. The model should not invent those control fields because it can generate plausible strings.
Separate references from content. A source identifier points to a record; a quoted passage contains evidence from that record. If the worker needs the actual text, the contract must say how authorised content is provided. A reference alone does not mean the receiver has inspected the source. Also define which fields the worker must preserve rather than reinterpret. A request identifier is a correlation aid, not a natural-language topic to rewrite. Field ownership prevents a downstream component from silently turning an input fact or control value into its own guess while retaining the same label.
3. Define the candidate-summary fields
The response contains contract version, request identifier, input source version, candidate draft identifier, summary text, claim-to-source references and unresolved output issues. If the worker reports a status, limit it to the states it can legitimately establish, such as candidate prepared or unable to produce a supported candidate. It cannot report editor approved simply because the text looks ready for review.
Keep generated wording separate from verified fields copied through the pipeline. A summary sentence can be checked against the approved numeric value and source status. If the model changes six to eight, the structural contract might still consider it a valid sentence; a semantic comparison is needed to detect the mismatch. That distinction should be visible in the review design. The contract provides a predictable container and references for inspection. It does not erase the difference between a syntactically acceptable object, an internally consistent object and an artefact whose statements are supported by the approved material.
4. Choose types and value ranges deliberately
Specify whether each field is a string, number, boolean, array or object under the chosen representation. Define allowed status values rather than accepting any persuasive phrase. A field intended to carry a list of source references should not sometimes contain one prose paragraph and sometimes a nested table unless the contract explicitly supports those alternatives. Predictable shape makes receiving components simpler to inspect.
Value ranges and units need meaning as well as types. A numeric count may require a non-negative integer under the classroom rule, while a monetary amount would need currency and a stated representation policy. Do not silently convert arbitrary strings into numbers merely to keep a run moving. The phrase six pending enquiries is not the same thing as the verified integer six from an approved count field. A real implementation may choose carefully specified conversions, but those conversions belong in the contract and tests. Implicit coercion creates behaviour that one component may expect while another interprets differently.
5. Distinguish missing, empty and unknown values
A missing property, an empty string and an explicit unknown value represent different conditions unless the contract says otherwise. Required means the property must be present under the schema rule. It does not automatically mean the value is non-empty or factually established. JSON Schema documentation explains required properties and object validation; this lesson's particular field choices are an original classroom design.
For the workshop date, choose a representation that preserves uncertainty clearly. One option is a status field such as not specified alongside the absent calendar value, with the allowed structure defined explicitly. Another contract might allow null for the value, but only if the permitted type and meaning include it. Do not assume null is interchangeable with an omitted field. The receiver needs to know whether the source lacked a date, the worker failed to extract it or the field is irrelevant to this task. Those conditions lead to different next steps and should not disappear into an unexplained blank.
6. Specify treatment of unexpected fields
Decide whether the interface permits additional properties, rejects them or preserves them in a separately defined extension area. In JSON Schema, listing properties alone does not automatically forbid every other property; the relevant additional-property rule must be specified for that purpose. Do not assume that a schema-looking document has the strictness you intended without checking its actual validation semantics.
For the classroom candidate response, an unexpected field called send_now should not become an instruction to execute an external action. Even if a receiving parser preserves it for diagnosis, the approved action scope remains unchanged. The contract can reject the object or ignore unsupported content under a clear rule, but neither path should grant authority. Unknown-field handling is therefore both a compatibility question and a control-boundary question. A receiver should consume only the fields whose meanings and uses it supports, rather than treating every generated key as a new feature or command from the workflow owner.
7. Define structural and semantic validation separately
Structural validation checks required properties, types, allowed values and the shape of nested records. Semantic validation checks relationships and meaning: the response request identifier matches the active request, the source version matches the approved basis and copied numbers match verified values. Factual review examines whether the summary faithfully represents the source, including qualifiers and status. These are distinct layers.
Create a three-column validation plan naming the check, evidence and failure route. A missing request identifier can be rejected structurally. A valid identifier belonging to another task fails the semantic association. A correctly associated summary that upgrades a proposed meeting to confirmed fails source fidelity. A single valid flag should not conceal which checks actually ran. The architecture needs enough granularity to explain why a candidate was returned and what component can repair it. A schema validator cannot establish every business fact, while a human source review need not replace simple mechanical checks that can be defined precisely.
8. Make error objects useful to the sender
An error response should identify the contract version, request reference where available, error category, affected field or relationship and next action. Avoid a generic invalid result that leaves the sender guessing whether the source was missing, the type was wrong or the task was out of scope. At the same time, avoid copying unnecessary private input or credentials into error details.
For the fictional request, an absent approved-source version could produce an input-contract error routed to the state owner. A candidate carrying the wrong request identifier could be rejected and retained for investigation without attaching it to another task. A source-fidelity problem could return to the draft owner with the unsupported claim identified. These distinctions make error handling part of the interface rather than an informal chat after something breaks. The contract should also define what remains unchanged after rejection, so a failed candidate cannot accidentally overwrite the last accepted draft while the process asks for a correction.
9. Version contracts without silently breaking consumers
A contract version identifies the meaning and structure a receiver is expected to understand. If a new required field or changed status meaning is introduced, decide how older consumers will handle it. Do not assume all components update at the same instant. A version field is useful only when the receiver checks and applies its supported-version policy rather than copying the value into a log and proceeding blindly.
Use a classroom change: version one carries source date wording, while version two adds a separately verified calendar date. An older consumer must not assume the new field was present or verified under the old rules. Preserve the original date wording and define the migration or compatibility path. The exact versioning strategy depends on the implementation, but the blueprint should state the intended behaviour. This protects the meaning of historical outputs as well as current processing. An old candidate should not appear to have passed new checks merely because the latest documentation describes a richer contract.
10. Build a contract test pack with expected failures
Prepare a valid request, a missing required identifier, a wrong-type count, an unsupported status, an extra action-like field and a valid-shaped response with a mismatched source version. Write which layer should catch each issue. Add a summary that preserves structure but changes proposed to confirmed, demonstrating why structural success does not prove factual support.
Keep the test pack fictional and identify expected outcomes before evaluating a component. A useful pack includes correct unknown handling as well as rejection cases. If a date is genuinely absent and the contract supports that state, the object should not fail merely because it looks incomplete. The test should establish whether the representation matches its rules, not force every source into a fully populated record. These cases can later guide implementation checks, but passing the paper exercise does not establish that an actual parser, validator or model integration already behaves as specified.
11. Trace a candidate through validation and review
Start with request R31 using source P2 and verified count difference six. The worker returns D3 with matching identifiers, a candidate summary and claim references. Structural checks pass. Semantic checks confirm the association and copied numeric value. The editor then checks that the prose describes the number according to its approved label and preserves the source's proposed or confirmed status.
Now alter one field at a time. Change the source version to P1, the count to eight, then the wording to imply guaranteed availability. Each variation fails a different check despite possibly remaining valid JSON. Record the route and owner rather than grouping them as model errors. A mismatch might arise in assembly, transport or a stale caller, not only in language generation. The contract design should help diagnose the boundary where the artefact stopped satisfying its requirements. This is why structured fields and evidence links are useful even when a human ultimately reviews the prose.
12. Deliver the interface contracts and validation matrix
The final package contains purpose, field definitions, ownership, types, unknown-value rules, extra-field handling, structural and semantic checks, error responses, version policy and test cases. Keep the request and candidate contracts separate, with a clear statement that model output is data for review rather than authority to act. Mark unverified implementation capabilities as requirements to confirm.
Another learner should be able to explain how a valid object can still be wrong and how an incomplete-looking object can be correct when its unknown representation follows the contract. That distinction is the key learning outcome. The next lesson examines timeouts across these component boundaries. A defined response shape will help, but it cannot establish that a slow or missing response means the receiving component did nothing. Contracts must describe not only values on successful paths, but also the evidence and states associated with failure, delay and uncertainty.
Candidate D3 can be valid JSON yet carry the wrong source version, change a verified6 to8 or upgrade a proposed meeting to confirmed. These fail different checks. A date marked not specified can be correct when the source lacks it and the contract defines that representation. An extra send_now field never grants external-action authority.
Write the workshop request and candidate-summary contracts with required fields, types, owners, unknown handling, additional-field policy and versions. Build a validation matrix for missing identifiers, wrong types, mismatched versions and unsupported prose. State the error route and unchanged record for each rejected candidate.
Notes stay in this browser. Avoid sensitive personal information.
Compare your answer · Self-review guide
A strong contract makes structure predictable while preserving uncertainty and field meaning. Required presence is not factual truth; missing, empty and null need explicit meanings. Semantic associations and source fidelity remain separate from schema checks. Unsupported generated fields cannot redefine authority, and rejected candidates do not overwrite accepted artefacts.
This is an indicative answer, not an automatic assessment of your written work. Check your reasoning, units and assumptions.
What does successful structural validation of a candidate establish?
Continue beyond the lesson

No Plan, No Future
Gabriel Nicolaev — CyGuru
Design structured input and output contracts
A companion for questioning how direction, planning and changing circumstances interact. Read it beside a plan you are willing to inspect and revise, with attention to the difference between purposeful action and the wish for certainty.
Specify versioned request and candidate-output contracts with field ownership, unknown-value rules and separate structural, semantic and source-fidelity checks. This optional companion supports reflection on planning and decisions. Technical behaviour must be checked against primary documentation and the exercise evidence; the book is not a technical implementation manual.
Read with this lesson’s decision question: What does successful structural validation of a candidate establish? Which part of the answer needs primary evidence rather than the companion’s perspective?
Return to Design structured input and output contracts. Revisit your response to this task: Write the workshop request and candidate-summary contracts with required fields, types, owners, unknown handling, additional-field policy and versions. Build a validation matrix for missing identifiers, wrong types, mismatched versions and unsupported prose. State the error route and unchanged record for each rejected candidate.
Add your response to the lesson notes ↑How to use this companion
A planning and judgement companion for this AI exercise. The book is not an AI implementation manual; technical behaviour, access and integrations must be checked against the relevant documentation.
An editorial pairing by theme, not a book chapter summary. Your lesson and exercise remain available independently of the book.
Sources & further study
Original Academy explanations, fictional examples and exercises. The primary sources below support the lesson concepts; they are not sources for every teaching scenario.
Reviewed 7 November 2026.
An academy practice exercise. Adapt it to your circumstances.
