Constraints & Guardrails

Set explicit rules, what to use, what to avoid, and what not to touch, so the model stays inside safe, correct bounds.

TL;DR

  1. Constraints are the rules the output must obey; list them explicitly as bullets.
  2. Use positive rules (what to use), negative rules (what to avoid), and scope rules (what not to touch).
  3. Guardrails prevent the common failure modes: new dependencies, broken APIs, and out-of-scope edits.

Kinds Of Rule

    Positive

    Name what the code should use so it fits your stack.

    - use the existing `logger`
    - use zod for validation
    Negative

    Name what to avoid so the model stops reaching for it.

    - do not add new dependencies
    - do not use `any`
    Scope

    Bound what the change may touch and when it is done.

    - only edit src/cart
    - stop when tests pass

Common Guardrails

    Dependencies

    Lock the toolbox to prevent surprise packages in your tree.

    - no new dependencies
    - prefer stdlib
    Public API

    Protect interfaces other code relies on from silent changes.

    - do not change exported signatures
    - keep return types stable
    Style & Patterns

    Keep new code consistent with the project's conventions.

    - named exports only
    - match existing error handling

Write Them Well

    Bullet, Do Not Bury

    A labeled list is followed more reliably than rules hidden in a sentence.

    Constraints:
    - rule 1
    - rule 2
    Be Concrete

    Name the specific thing, not a vague principle.

    "no new deps" > "keep it lightweight"
    Prioritize

    Lead with the rules that matter most for correctness and safety.

    Safety + correctness first,
    style last.

Verify The Rules Held

    Check Imports

    Scan for any dependency the model slipped in against your 'no new deps' rule.

    git diff package.json  # should be empty
    Check Scope

    Confirm the diff only touches files you allowed.

    git status  # only src/cart changed?
    Restate If Ignored

    If a rule was dropped, repeat it near your next instruction.

    "Reminder: no new dependencies.
    Remove the added package."

Tips

  1. Keep a reusable guardrail block ('no new deps, no API changes, match existing style') for routine edits.
  2. State scope limits for agents explicitly: which directories are in bounds and which are off-limits.

Warnings

  1. Rules buried in prose get missed; a bulleted 'Constraints:' list is followed far more reliably.
  2. Too many constraints can box the model into awkward code; keep the list to what truly matters.

In Practice

FAQ