concept

Structured response schema

A shape contract for JSON values. Required nullable properties distinguish explicit unknowns from omission. Supported schema subsets vary by provider. A strict native Python integer policy is narrower than JSON Schema integer semantics. Shape validation does not establish facts.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
JSON Schema: type, properties, required, additionalProperties, enum, minimum, maximum

Working Example

Example Snippetartificial-intelligence
def shape_errors(record):    if type(record) is not dict:        return ["object_required"]    if set(record) != {"item", "quantity", "unit"}:        return ["fields"]    errors = []    if record["item"] is not None and (type(record["item"]) is not str or not record["item"]):        errors.append("item")    q = record["quantity"]    if q is not None and (type(q) is not int or not 1 <= q <= 100):        errors.append("quantity")    if record["unit"] not in ("piece", "box", None):        errors.append("unit")    return errors
print(shape_errors({"item":"P1", "quantity":2, "unit":"box"}))print(shape_errors({"item":"P1", "quantity":"2", "unit":"kg"}))