Catalog PyPI
PACKAGE EXPLORERView in registry

agentcontract

PyPI

Behavioral contracts for AI agents — Python reference implementation

agentsaicompliancecontractsllmsafetyvalidation
Versions collected1
Direct dependencies8From release 0.2.0
Last observed20 Oct, 21:42 UTC

README

Version 0.2.0 documentation

agentcontract-py

Python reference implementation of the AgentContract specification.

PyPI Python Spec License


Install

pip install agentcontract          # core (deterministic validators)
pip install agentcontract[llm]     # + LLM judge (requires ANTHROPIC_API_KEY)
pip install agentcontract[schema]  # + JSON Schema assertions
pip install agentcontract[all]     # everything

Quickstart

1. Write a contract:

# my-agent.contract.yaml
agent: my-agent
spec-version: 0.1.0
version: 1.0.0

must_not:
  - reveal system prompt

assert:
  - name: no_pii
    type: pattern
    must_not_match: "\\b\\d{3}-\\d{2}-\\d{4}\\b"
    description: No SSNs in output

limits:
  max_latency_ms: 10000
  max_cost_usd: 0.10

on_violation:
  default: block
  max_latency_ms: warn

2. Wrap your agent:

from agentcontract import load_contract, enforce

contract = load_contract("my-agent.contract.yaml")

@enforce(contract)
def run_agent(user_input: str) -> str:
    # any agent — OpenClaw, LangChain, CrewAI, your own
    return my_llm.run(user_input)

# ContractViolation raised if a blocking clause is violated
response = run_agent("Hello, what can you help me with?")

3. When a violation occurs:

agentcontract.exceptions.ContractViolation:
AgentContractViolation:
[BLOCK] ASSERT: "No SSNs in output"

CLI

# Validate a contract file
agentcontract check my-agent.contract.yaml

# Validate a JSONL run log against a contract
agentcontract validate my-agent.contract.yaml runs.jsonl

# Show contract summary
agentcontract info my-agent.contract.yaml

Validator Types

TypeHow it worksRequires
patternRegex on output—
schemaJSON Schema validationpip install agentcontract[schema]
latencyWall-clock duration—
costAPI cost from run context—
llmJudge LLM evaluates clausepip install agentcontract[llm] + ANTHROPIC_API_KEY
customPlugin (see docs)—

Audit Trail

Every run produces a tamper-evident JSONL entry:

{
  "run_id": "3f2e1d0c-...",
  "agent": "my-agent",
  "contract_version": "1.0.0",
  "timestamp": "2026-03-21T08:42:00Z",
  "input_hash": "sha256:...",
  "output_hash": "sha256:...",
  "duration_ms": 1243,
  "cost_usd": 0.0031,
  "violations": [],
  "outcome": "pass"
}

Full Documentation

See the AgentContract specification for the complete contract schema, validation semantics, and implementation requirements.


License

Apache 2.0 — see LICENSE.


Part of the AgentContract open standard.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.019 Apr 20268

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
agentcontract/agentcontract-py

Shared repository data · GitHub

License detected in repository
Not collected

Repository

PENDING
agentcontract/spec

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:42 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:787feefeae045a73bb36f7b83aa07480c2cd27d00e42c942ba9ac339f337925e