Specifications first, code second

Pedro's L3 Law for spec-driven development with AI agents

Pedro Santos

Talk · Software Crafters Barcelona 2026

Given under the name Pedro's L3 Law. The law is now called Pedro's Law.

Yes, I named it after myself — so that nobody else gets the blame.

The loop that we all know

prompt → code → "no, not like that" → prompt → code → "almost" → prompt …
  • The code works after the tenth prompt.
  • Where are the decisions now?
  • Spec-driven development says: write the specification first.
    It does not say what to do with the prompts after the specification.

Prompt-local knowledge

  • Knowledge that influenced the implementation but cannot reliably be recovered, evaluated, or reused.

  • It lives in the conversation, the agent session, the tool output, the uncommitted changes, the review comments, or the generated code.

  • Example: prompt 3 says "use the repository abstraction, not the database". Prompt 11 bypasses it to fix a failing test. Nobody notices.

If this prompt disappears, where is the knowledge it introduced?

The law

Use as many rich, iterative prompts as you need to create the specifications.

Then with only one prompt: generate the code and associated unit tests from those specifications, without introducing new requirements or design decisions

Two kinds of prompting

Specification Implementation
Prompts As many as you need One controlled prompt
Purpose Explore, challenge, decide Generate the code from the decisions
Output Requirements, contracts, ADRs, acceptance and fitness tests Code and unit tests
Can it change the specification? Yes No. It is read-only.

Who does what

The agent

  • Inspects the repository
  • Plans the change
  • Writes the code and the unit tests
  • Runs the checks
  • Corrects its own defects

The human

  • Defines the outcome and the scope
  • Writes and approves the specification
  • Defines the quality gates
  • Approves the boundaries
  • Stays accountable

Engineers spend less time directing individual code changes and more time designing the specifications, constraints, evaluation mechanisms, and agent workflows that produce reliable code.

What belongs in the specification

Depending on risk, a specification can include:

  • Functional and non-functional requirements
  • Scope and non-scope
  • Logical and physical architecture
  • System, service, data, and team boundaries
  • Architecture Decision Records
  • Security, privacy, and compliance requirements
  • Observability and operational expectations
  • Deployment, rollback, and recovery expectations
  • Milestones and implementation sequencing
  • Acceptance, end-to-end, contract, and fitness tests
  • Failure scenarios and measurable quality thresholds

If a prompt holds a decision that matters after the session, move it into the spec or into an executable check.

Proportional, and in thin slices

Tier Typical changes Minimum specification
Low Internal refactoring, copy, an isolated bug fix Behavior, scope and non-scope, boundaries touched, acceptance tests
Medium A new feature or endpoint in one service, an internal contract, a new dependency Low, plus: API contract, error and edge cases, fitness checks, an ADR for each architecture decision
High Public contracts, data schemas, security, sensitive data, infrastructure, cross-team changes Medium, plus: architecture, security and privacy, observability, deployment and rollback, a named approver

Refine the specification one thin vertical slice at a time. Not the whole system up front.

Example: a High-tier slice

  • Spec: orders-api/list-open-orders@v5 — GET /v1/customers/me/orders
  • Open: status = OPEN. Other statuses are excluded.
  • Ownership: the customer ID comes from the identity. No customer ID in the path.
  • Empty: 200 with items: []. Unauthenticated: 401, standard error schema.
  • Order: ascending by id, stable across pages. Last page: nextCursor: null. Bad paging: 400.
  • Boundary: use OrderRepository. No direct database access. See ADR-20261009T1530Z-order-repository-boundary.
  • Acceptance tests: only own open orders; other statuses excluded; empty; 401; next page in order; last page; 400.
  • Fitness checks: no database import in the API layer; uses OrderRepository; spec and oracle files unchanged.
  • High-tier extras: no order data in logs; error-rate and p95 alerts; feature flag for rollback; a named service owner approves.

The controlled implementation prompt

Implement orders-api/list-open-orders@v5 in the current repository from the approved specification and repository context. Generate the production code and associated unit tests. Run the approved acceptance and fitness checks. You MAY correct implementation defects, but you MUST NOT add requirements, change the acceptance tests or fitness functions, bypass the repository boundary, or make new architecture decisions. Stop and escalate if the specification is incomplete, contradictory, or cannot be implemented safely.

Small on purpose: the decisions are already in the specification.

When the result is wrong: which failure is it?

Implementation failure Specification failure
What The spec is correct. The code does not satisfy it. The code exposes a gap, a contradiction, or an impossible requirement.
Who acts The agent corrects the code, inside the same prompt. The agent stops and escalates. A human classifies.
Then Run the gates again. Revise and version the spec. Regenerate the slice.

Never weaken a test, bypass a boundary, or silently reinterpret a requirement to get green.

Do not ask the agent to protect the tests. Lock them.

When a test fails, the fastest path to green is often to edit the test.
"Do not change the tests" in a prompt is only a request.

Lock the spec, the acceptance tests, and the ADRs at three layers:

Layer Control Effect
Agent sandbox No write access to those folders The agent cannot change them
CI Fail the build if an implementation change touches them A change cannot merge
Code review CODEOWNERS on those folders A named human approves each change

The oracle is not the generated unit test

  • The agent writes the unit tests with the code. They share its assumptions.
  • The oracle: the human-approved acceptance tests and fitness functions.
  • Passing generated unit tests is not evidence of acceptance.
  • Test-first still works: write the oracle before the implementation prompt.

Traceability: every change points to its spec

Spec: orders-api/list-open-orders@v5
ADR: ADR-20261009T1530Z-order-repository-boundary
Prompt: <prompt template ID@version>
Baseline: <repository commit>
Agent: <agent/tool version>
Model: <model version>
Generated: <UTC timestamp>
Evaluation: <link to evaluation report>
  • In the pull request template.
  • No sequential IDs. Two parallel agents both take "ADR-013".
  • ADRs: timestamp + slug. Specs: path + slug + @vN.

How do you know that it works?

  1. Specification traceability: pull requests linked to a spec version
  2. Human corrective prompts per pull request, after the implementation prompt
  3. Regeneration success: regenerated slices that pass the same gates
  4. Post-merge defects that the spec or the gates did not catch

Autonomous agent iterations are normal. Human corrective prompts are the signal.

Try it on Monday

  1. Take your next small feature. Write the acceptance tests before you prompt.
  2. Give the agent one controlled prompt. Count every corrective prompt after it.
  3. For each corrective prompt, ask: where is the knowledge it introduced? Move it into the spec.

Takeaway

Humans engineer the conditions for reliable software generation.

Agents drive the implementation within those conditions.

Questions?

Specs are the new source code.