A data contract is a declared blueprint for exchanged data: its fields, types, required attributes, constraints, and intended meaning. It makes a producer’s output a predictable input for downstream code, whether the exchange is an event, an AI response, or a pipeline hand-off. section 8.3.2 section 9.2.1
In Python pipelines, a Pydantic model can implement the contract. The model defines the expected shape, validates returned values, and gives an LLM or ordinary function a typed boundary. A prompt can serialize that schema and state transformation rules; response-handling code then parses results, handles errors, and passes usable objects downstream. section 8.3.2 section 12.1.1
Use a contract to make each hand-off explicit:
- Define output fields, types, and constraints before implementing extraction, transformation, or loading. section 8.3.2
- Inject the expected schema into an AI extraction or transformation prompt and require one matching object. section 8.2.2 section 8.3.3
- Validate and handle failures at the boundary, using defaults or recorded status rather than losing the remaining pipeline results. section 8.3.3 section 12.1.2
- Keep orchestration in predictable code while limiting LLMs to interpreting messy content into structured output. section 12.1.1
Article extraction contract
An ExtractedArticle model declares source, title, short_summary, and publish_date. A schema-based prompt directs extraction from raw article JSON and requires exactly one matching object, producing structured rows ready for later sentiment analysis and transformation. section 8.2.2
Event hand-off contract
An order-created event can require event_type, order_id, user_id, total_amount, currency, and created_at. Producers emit this agreed JSON shape so consumers can identify the action and process its context reliably. section 9.2.1
Figure 8.3 This diagram illustrates the three key components of the AI harness pattern: the data contract, which defines the structure and constraints of the expected output; the prompt (logic layer), which encodes transformation rules in natural language; and the response handling code, which operationalizes the output and connects it back into the data pipeline. Together, these components create a repeatable, flexible, and semantically aligned framework for using AI in structured data workflows.
The harness diagram places the contract beside the prompt and response-handling code, showing how schema, transformation logic, and operational validation work together. section 8.3.2




