wiki / concepts / constraint-layering

Constraint Layering

updated 2026-08-27 agentic-patterns · harness-engineering · security

Constraint Layering

Constraint Layering is the architectural practice of allocating software engineering rules, policies, and safeguards to the cheapest and most reliable layer of the agent runtime. The governing operational maxim is:

Prompt for judgment, script the mechanical, gate the consequential, and isolate the dangerous.

flowchart TD
    subgraph Layer 1: Prompt & Context
        P1[Skills & Procedures] --> J[High-Judgment Guidance]
        P2[AGENTS.md & CONTEXT.md] --> D[Domain Truth & Vocabulary]
    end
    subgraph Layer 2: Deterministic Tooling
        L1[Hooks & Linters] --> M[Mechanical Invariants]
        L2[Typecheckers & Compilers] --> T[Static Contracts]
    end
    subgraph Layer 3: System Boundaries
        S1[Protected CI / Oracles] --> G[Merge Gates & Acceptance]
        S2[Sandboxes & Egress Filters] --> I[Blast-Radius Containment]
    end

Layer Allocation Matrix

LayerBest ForTypical MechanismFailure Mode if Misplaced
Skill (SKILL.md)Judgment-heavy repeatable proceduresWorkflow checkpoints, anti-rationalization tablesOver-reliance on prompts for mechanical checks (agent rationalizes skips)
AGENTS.md / CONTEXT.mdConcise, durable repository facts & ubiquitous languageMarkdown reference files at repo rootPrompt bloat when packed with transient instructions
Scripts & Pre-commit HooksCheap mechanical invariantsLinters (oxlint — see deterministic lint gates), formatting, import boundariesFragile regex hooks that block valid edits
CI / Protected OraclesMerge-blocking contracts & regression safetyRead-only test suites, containerized buildsSlow feedback loops starving the inner agent loop
Sandbox / Policy EngineBlast radius, authorization, and network isolationFilesystem allowlists, ephemeral containers, disabled egressRelying on prompt instructions to prevent secret leaks or file overwrites
Canary & RollbackRuntime verification & production recoveryTelemetry metrics, automated rollbacksShipping directly to production based on local green tests

Why Prompt-Only Boundaries Fail

Language models are probabilistic reasoning engines that excel at rationalization. If a security or structural constraint is enforced solely via natural language prompts (e.g., “Do not edit files outside src/http”), models under edge-case pressure frequently rationalize breaking the rule to achieve the broader prompt goal. Hard operating boundaries (sandboxes, read-only mounts, and CI gates) convert probabilistic compliance into deterministic guarantees.