AI320 — Original on-site preparation

Independent written study. All essential explanations and optional model reasoning for this chapter are on this page. References are optional further study. No degree, professional approval or observed competence is conferred.

Turn a generated object into a checked answer state

The earlier notation {status:answered,answer:All orders are refundable,sources:[P7]} is a schematic object, not literal JSON: keys and string values need double quotes. This distinction matters before discussing meaning. The literal JSON {"status":"answered","answer":"All orders are refundable","sources":["P7"]} can parse successfully and still make an unsupported claim. A parser constructs data; a schema checks a representation contract; neither establishes permission or entailment.

Define the result states before writing the prompt. In this teaching contract, answered has a nonempty answer and at least one source ID; insufficient_evidence has an empty answer and empty sources; conflict has an explanation and at least two source IDs. The conflict rule counts references, rather than proving that their contents disagree. A separate evidence review must establish the actual conflict and its applicability. The application should retain these states through the UI and action boundary instead of converting every result into an authoritative answer string.

Construct the allowed ID set from the exact source snapshot admitted to this request after authorization, effective-date and version checks. Do not use every syntactically valid ID in the database. A source becoming inaccessible between retrieval and release needs a stated revalidation policy; a cache is another copy subject to the same boundary. A model may propose references but cannot enlarge this set. Bind any claim-support review to the particular answer, source versions and locators: approval of an earlier draft does not approve a later changed claim.

import json

def reject_constant(value):
    raise ValueError("Nonstandard numeric constant")

def unique_object(pairs):
    result = {}
    for key, value in pairs:
        if key in result:
            raise ValueError("Duplicate object key")
        result[key] = value
    return result

def answer_contract(raw, allowed_ids):
    if type(raw) is not str or len(raw) > 10000:
        raise ValueError("Invalid or oversized response")
    obj = json.loads(raw, object_pairs_hook=unique_object,
                     parse_constant=reject_constant)
    if type(obj) is not dict or set(obj) != {"status", "answer", "sources"}:
        raise ValueError("Unexpected fields")
    state, answer, sources = obj["status"], obj["answer"], obj["sources"]
    if type(state) is not str or type(answer) is not str or type(sources) is not list:
        raise ValueError("Invalid field types")
    if len(sources) > 20 or any(type(s) is not str or s not in allowed_ids for s in sources):
        raise ValueError("Invalid source reference")
    if len(set(sources)) != len(sources):
        raise ValueError("Duplicate source reference")
    if state == "answered":
        valid = bool(answer.strip()) and len(sources) >= 1
    elif state == "insufficient_evidence":
        valid = answer == "" and sources == []
    elif state == "conflict":
        valid = bool(answer.strip()) and len(sources) >= 2
    else:
        valid = False
    if not valid:
        raise ValueError("State invariant failed")
    return obj

The length bound is one modest application constraint, not a complete parser resource defense. Transport byte limits, timeouts and concurrency budgets also belong at their own boundaries. This example rejects duplicate keys instead of silently allowing one value to replace another. Python type hints alone would not enforce these runtime conditions. Display answer text through the UI framework's text mechanism; do not treat it as executable HTML, SQL, a shell command or an authorized tool request. The returned object contains no action permission.

Trace a current-policy answer whose allowed set is {P7,P8}. An invented P9 fails identity validation. A genuine P7 with an answer omitting its unused-item and thirty-day conditions passes this representation check but fails substantive support. An empty answered result fails the state invariant; the declared empty insufficient-evidence object passes. A conflict citing only P7 fails even if its prose says that two documents disagree. Two IDs passing the check still require inspection of the actual contradictory propositions.

Optional changed contract: complete reasoning

Change the allowed set to {P8} after P7 access is withdrawn. The previously valid P7 representation now fails source validation; hiding its citation after releasing the same answer would not repair the boundary. Change a two-source conflict to [P8,P8]: duplicate rejection prevents manufacturing two distinct references. If P8 and P10 are both authorized but describe different transaction dates, their different deadlines do not establish a same-case conflict. Establish temporal applicability before choosing conflict or answered. A correct parser result does not resolve that interpretation. For the original unquoted schematic object, parsing fails first; replace it with actual JSON before reasoning about schema or support.

Optional criteria, one point each: distinguish schematic notation from literal parsing; enforce field/state invariants; bind source identity to current authorized provenance; assess claim support and action permission separately. Explain all four for four points.

Optional source references

These sources support the explanations; reading them is optional. Original Academy examples are fictional. Historical attributed readings remain preserved.