The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← AI 320 — Applied AI, Retrieval and Reliable Automation

Weeks 3–5

Prompt contracts, structured outputs and validation

Learning objectives

  • Explain and trace the mechanisms in prompt contracts, structured outputs and validation.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

A prompt should state the task, available evidence, constraints and required response structure. Delimit instructions from source material, but do not assume delimiters create a security boundary. A model can still misunderstand or follow hostile content. The application must enforce permissions, validate outputs and decide which actions are allowed.

Structured output makes some failures easier to detect. A JSON object with an answer and source identifiers is easier to validate than unrestricted prose. Parsing JSON checks syntax; validating fields checks shape; checking each citation against retrieved evidence checks grounding. These are separate layers. A valid object can still contain a false claim. Do not use eval to parse generated content or execute model-supplied code.

Keep privileged configuration outside untrusted input. A document may contain text telling the assistant to ignore its task or reveal secrets. That text is evidence to analyze, not an instruction with authority over the application. Reject unexpected fields and constrain allowed values where appropriate. If a model returns an unsupported action, the safe response is a controlled failure or clarification, not a permissive guess. Test empty outputs, extra fields, missing citations, malformed numbers and contradictory evidence.

Worked reasoning The validator rejects an invented source ID and unexpected fields. It does not prove that policy A actually supports the answer; evidence review is still required. An empty sources list is syntactically permitted here so abstention can be represented, but a complete contract should distinguish an evidence-backed answer from an abstention and require sources for positive claims.

Extended teaching and laboratory

Structured output constrains representation: fields, types, allowed values and sometimes relationships among fields. It does not prove that the cited passage supports the answer. Enforce an answer contract with distinct states such as answered, insufficient_evidence and conflict. A positive answer needs valid, authorized source identifiers and support for every material claim.

Reject unexpected fields when they could smuggle an action instruction through an otherwise valid object. Validate identifiers against the retrieved authorized corpus rather than accepting any well-formed string. Keep validation failures visible in evaluation.

Worked problem Output is {status:answered,answer:All orders are refundable,sources:[P7]}. P7 says unused items may be refundable within 30 days. Evaluate syntax, source identity and entailment separately.

Step-by-step reasoning 1. The object might satisfy the declared schema if those fields and status are allowed. That is only structural validity.

  1. Verify P7 exists, is the correct version and is accessible to the requester. An invented or unauthorized identifier fails provenance.
  1. The unconditional all-orders claim exceeds P7’s restrictions. Correct it to the bounded conditions or mark unresolved exceptions.
  1. If the workflow cannot establish applicability, return a distinct insufficient-evidence or conflict state rather than an unsupported positive answer.

Apply the idea

Output is {status:answered,answer:All orders are refundable,sources:[P7]}. P7 says unused items may be refundable within 30 days. Evaluate syntax, source identity and entailment separately.

The source ID is genuine but refers to an expired policy. What should the validator or workflow establish before answering a current-policy question?

Read the worked reasoning

Check temporal applicability, superseding versions and the relevant transaction date. A genuine historical source can support a historical claim while failing a current-policy claim. Preserve the version and locator in provenance. Do not silently rewrite a historical transaction under a newer policy without a stated rule.

Check understanding

What does valid JSON fail to establish?

  1. Truth, source support and authorization
    Feedback

    Syntax validation is weaker than semantic and permission checks.

  2. That the text follows JSON syntax
    Feedback

    A successful parser does establish syntactic validity under its rules.

  3. That a parser can construct a data object
    Feedback

    Parsing creates data, not evidence of its truth.

Further reading

Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Review the assigned language and software-boundary material. Treat prompt examples as task specifications, not as guarantees of model compliance.

My learning →