§0statement
← All patterns

Typed spec, not free HTML

Restructure the task so the error cannot happen.

§1why

Why it works

An agentAn AI program that writes and changes code, for example Claude Code or Cursor. On this site, "agent" means a coding agent. writing free HTML can invent a colour, a spacing value or a component. An agent filling a typed specA structured description of a page that a script turns into HTML. The agent fills the spec. It does not write the HTML. can only choose from what the type allows. A script composes the page from vetted parts and returns a verdict. The agent selects and fills; scripts build and judge.

§2example

Copy this

ts
type PageSpec = {
  template: "account-overview" | "payment-form";
  sections: Array<
    | { part: "BalanceCard"; accountId: string }
    | { part: "TransactionList"; accountId: string; limit: 10 | 25 }
    | { part: "Alert"; status: "danger" | "warning" | "success"; textId: string }
  >;
};
// The agent returns a PageSpec. compose(spec) builds the page and returns a verdict.
§3breaks

Where it breaks

A new screen needs a new part. Without a proposal path the agent is stuck or goes back to free HTML.

§4cases

Used in: Case 5.