Course overview/From question to specification2 of 3

Write the model contract

Write the model contract

Write the six fields that fix a model's answer before its SQL exists.

Fix the answer before the query

A model contract is a short file with six fields: Question, Grain, Keys, Metric, Filters, and Not included. It prevents the same request from changing shape every time an agent or analyst opens it.

For the weekly category model, grain is a sentence such as "one row per category per week." Keys are category and week start. The metric must name the expression and column, not the word revenue. Filters must separately decide the fate of cancelled orders and NULL statuses. Not included tells later readers where the model stops.

Your task

Copy docs/contracts/TEMPLATE.md to docs/contracts/weekly_category.md. Fill every field for the weekly category request. Choose a revenue column, explain the choice, and write decisions for cancelled and missing statuses.

Check your understanding

  • Name the six fields of a model contract, in order.
  • Why does "Metric: revenue" fail as a contract field in this project?
  • You paste docs/contracts/weekly_category.md into an agent's context, then ask it to "add a filter for the top five countries." Why does the contract make that request safer?

Do it with your agent

Say next lesson. Do the contract by hand, then say review my work. The agent should check the exact path, six complete fields, named metric, stated grain, and both status decisions.

Sign up to our newsletter

Practical updates on open-source data pipelines, AI analysts, governance, and what we are shipping at Bruin.

The signup form is hosted by Brevo. Allow marketing cookies to load it.