Find the boundary between specification and intent.
Constrain interviews engineers about their problem and produces five artifacts that feed directly into downstream tools. The prompt gives an AI agent the context to build the right thing. The constraints, trust policy, component map, and schema hints give downstream systems the structured data they need to scaffold contracts, orchestrate circuits, arbitrate trust, and build schemas.
pip install -e ".[anthropic]" # Anthropic backend (default)
pip install -e ".[openai]" # OpenAI-compatible backend
pip install -e ".[mcp]" # MCP server
pip install -e ".[all]" # Everything
Requires Python 3.12+ and an API key for your chosen backend.
Constrain supports Anthropic (default) and any OpenAI-compatible API, including local models.
# Anthropic (default)
export ANTHROPIC_API_KEY=sk-...
constrain
# OpenAI
constrain --backend openai --model gpt-4o
# Local model via OpenAI-compatible API
CONSTRAIN_BACKEND=openai OPENAI_BASE_URL=http://localhost:11434/v1 constrain --model llama3
Environment variables: CONSTRAIN_BACKEND=anthropic|openai, CONSTRAIN_MODEL=<model-name>
Randomized per session so descriptions must be robust to all of them.
constraints:
- id: C001
boundary: "file upload endpoint"
condition: "files > 10MB rejected before processing"
violation: "large file consumed memory, crashed worker"
severity: must
rationale: "production incident 2024-03"
classification_tier: null
affected_components: ["api-gateway"]
| Artifact | Consumer | Purpose |
|---|---|---|
prompt.md | Pact | System briefing for decomposition |
constraints.yaml | Pact, Sentinel | Contracts and violation detection |
trust_policy.yaml | Arbiter | Trust arbitration configuration |
component_map.yaml | Pact, Baton | Topology for decomposition and circuits |
schema_hints.yaml | Ledger | Schema scaffolding from interview hints |
constrain # Start a new session (or resume incomplete)
constrain new # Always start fresh
constrain resume # Resume the most recent incomplete session
constrain show # Display artifacts from the last completed session
constrain list # List all sessions
constrain validate # Validate all artifacts for internal consistency
constrain export -f <format> # Export skeletons for downstream tools
constrain mcp-server # Run MCP server (stdio transport)
constrain validate checks internal consistency across all five artifacts: component names match between component_map.yaml and constraints.yaml, authority domains align between trust_policy.yaml and component_map.yaml, edge/dependency references resolve, trust floor ordering is valid, and annotation requirements are satisfied.
Generate skeletons for downstream tools from your Constrain artifacts.
constrain export --format pact # task.md skeleton from prompt.md
constrain export --format baton # baton.yaml skeleton from component_map.yaml
constrain export --format arbiter # arbiter.yaml skeleton from trust_policy.yaml
constrain export --format ledger # schema_hints.yaml skeleton for Ledger
| Format | Source Artifact | Output |
|---|---|---|
pact | prompt.md | task.md skeleton for Pact decomposition |
baton | component_map.yaml | baton.yaml with nodes, edges, data access |
arbiter | trust_policy.yaml | arbiter.yaml with trust config, classifications |
ledger | schema_hints.yaml | Ledger schema scaffolding with field hints |
Sessions save to .constrain/sessions/ in the current directory. Ctrl+C saves and exits (resumable). Ctrl+D ends the current phase early.
Constrain exposes sessions and artifacts to AI assistants via the Model Context Protocol.
# Standalone
constrain-mcp
# Via CLI
constrain mcp-server --project-dir /path/to/project
# Register with Claude Code
claude mcp add --scope user --transport stdio constrain -- constrain-mcp
Tools: constrain_list_sessions, constrain_show_session, constrain_show_artifacts, constrain_search_sessions
Resources: constrain://sessions, constrain://session/{id}, constrain://artifacts/{id}