cipeizheng/agent-guardrail

An explainable policy analyzer and enforcement gateway for AI agents.

Python

0

39 commits

updated Sep 15, 2026

See the code

README

Agent Guardrail

A security control layer for AI agents.

English | 简体中文

Version Python Status License

Agent Guardrail checks model requests, model output, tool calls, and tool results before they proceed to the next step, then allows, records, or blocks them according to YAML rules.

It preserves relationships among messages, model calls, and tool calls, and produces masked findings, error messages, and audit records.

Project status

The current version is v0.1.0 alpha. The project provides in-process and HTTP Gateway integration, supports OpenAI, Anthropic, and MCP, and supports separate deployment of policy analysis.

Quick start

Requirements: Python 3.12 or later and uv.

git clone https://github.com/cipeizheng/agent-guardrail.git
cd agent-guardrail
uv sync --frozen --extra gateway --dev
uv run python examples/secret_email_demo.py

The demo uses local model and tool implementations, so it needs no API key. The model call runs, while the email tool call is blocked before execution. The final lines are:

policy decision: block
model executions: 1
send_email executions: 0

Policy configuration

Policies use the version-3 YAML format. This example checks a send_email call and blocks it before execution when its arguments contain a secret or other sensitive credential.

version: 3
scopes: [pending]
rules:
  - id: prevent-secret-email
    action: block
    events:
      call: {kind: tool_call_proposal, domain: pending}
    where:
      all:
        - tool: {binding: call, name: send_email}
        - detector:
            id: secret_scan
            capability: secrets
            inputs:
              - value: {field: [call, payload, arguments]}
                encoding: canonical_json
    finding:
      code: secret_exfiltration
      message: The proposed tool call contains secret material.
      subjects: [call]
      evidence: [{source: detector, id: secret_scan}]

The loader checks the format, references, resource limits, and available detection capabilities before activating a policy. See the Policy authoring guide for the complete syntax.

Built-in detection capabilities

The default local profile provides the following local checks without model downloads or external services. The names in the table are used in policy files:

What it checksPurposePolicy name
Secrets and credentialsFinds private keys, cloud credentials, and API tokenssecrets
Personal informationFinds fixed types such as email, phone, identity, and financial numberspii
Prompt injection signalsFinds high-signal instruction overrides, prompt disclosure, and role changesprompt_injection
Invisible or confusing textFinds Unicode controls, zero-width characters, and limited mixed-script tricksunicode_security
Python code structureReports imports, risky calls, and syntax factspython_ast_ipython
Hidden web contentFinds hidden HTML, comments, and bounded encoded contenthidden_content
Numeric or length rangesChecks numbers, text, arrays, and objects against boundsnumber_in_range, length_in_range
URL host allowlistsChecks whether an HTTP(S) URL uses an allowed hosturl_host_allowed
Approximate text matchingFinds text within a bounded edit distancefuzzy_contains

Other detection capabilities, integration methods, and status are maintained in the capability matrix; detailed setup is in the capability reference and operations guide.

Detection results are signals. Rules should also use the data source, destination, authorization, and relationships among the message, model call, and tool call involved in the protected operation.

Deployment and security

Guardrail checks events submitted through its SDK and requests handled by its Gateway. With the SDK, application code reads the returned decision before performing the operation; the Gateway enforces that ordering for model and MCP requests. Agent code that can run shell commands, arbitrary code, direct network calls, or host operations still requires a separate sandbox with default-deny egress, minimal temporary storage, and resource limits. Keep provider or tool credentials and audit storage outside that sandbox. The security model and operations guide define the responsibility split.

Deployment details and responsibility boundaries are described in the operations guide and security model. Future work is listed in the roadmap; the current architecture contract defines current behavior.

Documentation

ReadFor
Documentation mapThe shortest path for each task
Architecture overviewThe end-to-end Event, Policy, Runtime, and Enforcement flow
Policy authoringWriting version-3 YAML
Integration guideConnecting application code, model clients, and MCP
Capability referenceDetector and Predicate contracts
Gateway protocolHTTP, streaming, and MCP wire behavior
Responses state-layer designprevious_response_id state interface and external state-owner boundary
Operations guideProfiles, environment variables, Docker, audit, and health
Security modelAssets, trust boundaries, and T01–T10
Separate analysis service designDeploying policy analysis separately
Long-session capacity evaluationRegressing full, incremental shadow/active, and Remote Core v4 paths

Development

uv sync --frozen --extra gateway --dev
uv run pytest --cov=agent_guardrail --cov-report=term-missing
uv run ruff check .
uv run pyright
uv build
git diff --check

See CONTRIBUTING.md for the development workflow.

License

Agent Guardrail is available under the MIT License. Optional detector assets and dependencies retain their upstream licenses; consult the operations guide before deploying a model profile.

cipeizheng/agent-guardrail

An explainable policy analyzer and enforcement gateway for AI agents.

Python

0

39 commits

updated Sep 15, 2026

See the code

README

Agent Guardrail

A security control layer for AI agents.

English | 简体中文

Version Python Status License

Agent Guardrail checks model requests, model output, tool calls, and tool results before they proceed to the next step, then allows, records, or blocks them according to YAML rules.

It preserves relationships among messages, model calls, and tool calls, and produces masked findings, error messages, and audit records.

Project status

The current version is v0.1.0 alpha. The project provides in-process and HTTP Gateway integration, supports OpenAI, Anthropic, and MCP, and supports separate deployment of policy analysis.

Quick start

Requirements: Python 3.12 or later and uv.

git clone https://github.com/cipeizheng/agent-guardrail.git
cd agent-guardrail
uv sync --frozen --extra gateway --dev
uv run python examples/secret_email_demo.py

The demo uses local model and tool implementations, so it needs no API key. The model call runs, while the email tool call is blocked before execution. The final lines are:

policy decision: block
model executions: 1
send_email executions: 0

Policy configuration

Policies use the version-3 YAML format. This example checks a send_email call and blocks it before execution when its arguments contain a secret or other sensitive credential.

version: 3
scopes: [pending]
rules:
  - id: prevent-secret-email
    action: block
    events:
      call: {kind: tool_call_proposal, domain: pending}
    where:
      all:
        - tool: {binding: call, name: send_email}
        - detector:
            id: secret_scan
            capability: secrets
            inputs:
              - value: {field: [call, payload, arguments]}
                encoding: canonical_json
    finding:
      code: secret_exfiltration
      message: The proposed tool call contains secret material.
      subjects: [call]
      evidence: [{source: detector, id: secret_scan}]

The loader checks the format, references, resource limits, and available detection capabilities before activating a policy. See the Policy authoring guide for the complete syntax.

Built-in detection capabilities

The default local profile provides the following local checks without model downloads or external services. The names in the table are used in policy files:

What it checksPurposePolicy name
Secrets and credentialsFinds private keys, cloud credentials, and API tokenssecrets
Personal informationFinds fixed types such as email, phone, identity, and financial numberspii
Prompt injection signalsFinds high-signal instruction overrides, prompt disclosure, and role changesprompt_injection
Invisible or confusing textFinds Unicode controls, zero-width characters, and limited mixed-script tricksunicode_security
Python code structureReports imports, risky calls, and syntax factspython_ast_ipython
Hidden web contentFinds hidden HTML, comments, and bounded encoded contenthidden_content
Numeric or length rangesChecks numbers, text, arrays, and objects against boundsnumber_in_range, length_in_range
URL host allowlistsChecks whether an HTTP(S) URL uses an allowed hosturl_host_allowed
Approximate text matchingFinds text within a bounded edit distancefuzzy_contains

Other detection capabilities, integration methods, and status are maintained in the capability matrix; detailed setup is in the capability reference and operations guide.

Detection results are signals. Rules should also use the data source, destination, authorization, and relationships among the message, model call, and tool call involved in the protected operation.

Deployment and security

Guardrail checks events submitted through its SDK and requests handled by its Gateway. With the SDK, application code reads the returned decision before performing the operation; the Gateway enforces that ordering for model and MCP requests. Agent code that can run shell commands, arbitrary code, direct network calls, or host operations still requires a separate sandbox with default-deny egress, minimal temporary storage, and resource limits. Keep provider or tool credentials and audit storage outside that sandbox. The security model and operations guide define the responsibility split.

Deployment details and responsibility boundaries are described in the operations guide and security model. Future work is listed in the roadmap; the current architecture contract defines current behavior.

Documentation

ReadFor
Documentation mapThe shortest path for each task
Architecture overviewThe end-to-end Event, Policy, Runtime, and Enforcement flow
Policy authoringWriting version-3 YAML
Integration guideConnecting application code, model clients, and MCP
Capability referenceDetector and Predicate contracts
Gateway protocolHTTP, streaming, and MCP wire behavior
Responses state-layer designprevious_response_id state interface and external state-owner boundary
Operations guideProfiles, environment variables, Docker, audit, and health
Security modelAssets, trust boundaries, and T01–T10
Separate analysis service designDeploying policy analysis separately
Long-session capacity evaluationRegressing full, incremental shadow/active, and Remote Core v4 paths

Development

uv sync --frozen --extra gateway --dev
uv run pytest --cov=agent_guardrail --cov-report=term-missing
uv run ruff check .
uv run pyright
uv build
git diff --check

See CONTRIBUTING.md for the development workflow.

License

Agent Guardrail is available under the MIT License. Optional detector assets and dependencies retain their upstream licenses; consult the operations guide before deploying a model profile.