Skip to main content

gentrail

Governance SDK for AI agents. It captures compliance-evidence-grade telemetry from an agent run and, when enabled, enforces policy inline before a tool call executes.

A Go SDK with the same span shape lives in ../go/ (go get github.com/aigentrail/sdk/go).

Quickstart

pip install "gentrail[strands]"
export GENTRAIL_API_KEY="sk-..."
import gentrail
from strands import Agent

g = gentrail.init()
agent = Agent(model=model, tools=tools, hooks=[g.hook()])
agent("Reconcile the Q3 invoices")

That is the whole integration. init() reads the environment, builds the governance tracer and the policy enforcer, and hook() returns a Strands HookProvider that captures prompts, chain-of-thought, and tool calls, ships them over OTLP, registers the agent on its first invocation, and enforces verdicts before a tool runs. Use one hook() per agent. Whatever is not configured stays off: with no API key the agent still runs, capture-only.

OpenAI Agents SDK

pip install "gentrail[openai-agents]"
from agents import function_tool
from gentrail.openai_agents import enforcement_guardrail

@function_tool(tool_input_guardrails=[enforcement_guardrail()])
def run_sql(database: str, sql: str) -> str: ...

A tool input guardrail that asks the decide endpoint before the tool runs. BLOCK rejects the call with the policy message; GATE holds it until a human approves in the Gentrail dashboard.

LangChain / LangGraph

pip install "gentrail[langchain]"
from langchain.agents import create_agent
from gentrail.langchain import enforcement_middleware

agent = create_agent(
    model=model,
    tools=tools,
    middleware=[enforcement_middleware(agent_id="reporter")],
)

Agent middleware wrapping every tool call, sync and async. Same verdicts: a blocked or unapproved call becomes an error ToolMessage and the tool never executes.

Bring your own telemetry

Frameworks that emit OpenTelemetry GenAI telemetry natively (Strands with strands-agents[otel], Google ADK, Pydantic AI, LangChain with LANGSMITH_OTEL_ENABLED, the Vercel AI SDK) do not need the SDK to build spans: the Gentrail backend ingests gen_ai.*, ai.*, and OpenInference telemetry directly. This is the recommended integration for those frameworks. What the SDK still adds is client-side PII redaction and export to Gentrail:

import gentrail

gentrail.instrument()

instrument() attaches a GentrailSpanProcessor to your application's TracerProvider (pass yours with instrument(provider=...); a fresh one is installed only when none exists). The processor redacts PII from gen_ai.*, ai.*, and OpenInference input/output attributes before any value leaves the process, stamps aigentrail.redaction.applied on spans it changed, and ships them to the Gentrail collector over OTLP. Other exporters on the provider keep the raw spans. Without GENTRAIL_API_KEY it returns None and the app runs unchanged.

Inline enforcement stays separate: add the enforcement adapter for your framework (above) to get BLOCK and GATE verdicts before a tool runs.

Configuration

All through environment variables:

  • GENTRAIL_API_KEY: enables OTLP export of governance spans.
  • OTEL_EXPORTER_OTLP_ENDPOINT: collector base URL, default https://otel.gentrail.ai.
  • OTEL_EXPORTER_OTLP_HEADERS: standard OTel header list; when set it replaces the SDK's default Authorization: Bearer <GENTRAIL_API_KEY> header.
  • GENTRAIL_DECIDE_ENDPOINT: enables inline enforcement (see below).
  • GENTRAIL_REDACT_PII: set to false to disable client-side PII redaction.
  • GENTRAIL_GATE_TIMEOUT_SECONDS: how long a gated tool call waits for human approval, default 120.

If your application already configures an OpenTelemetry TracerProvider, the SDK attaches its exporter to it as an extra span processor instead of replacing it; a fresh provider is installed only when none exists.

PII redaction

The SDK redacts high-confidence PII (emails, SSNs, credit cards, AWS keys) from span input and output values before they leave the process, replacing each with a typed placeholder like [EMAIL], so the raw value never reaches the collector while the data class stays visible for governance. This applies to spans the SDK builds and, via GentrailSpanProcessor, to gen_ai.*, ai.*, and OpenInference attributes on spans your framework emits itself. On by default; opt out with GENTRAIL_REDACT_PII=false or instrument(redact=False).

Inline enforcement (opt-in)

The async backend evaluator only sees a trace after a tool has already run, so it can detect but never prevent. Enforcement happens here, in the before-tool-call hook: the SDK asks the backend for a verdict on the proposed tool call and stops it before it executes.

It is opt-in and fails open. Set both environment variables to turn it on:

export GENTRAIL_DECIDE_ENDPOINT="https://your-dashboard.example"
export GENTRAIL_API_KEY="sk-..."

With these set, a BLOCK verdict cancels the tool call (the agent receives an error tool result and the tool never runs). A GATE verdict also stops the call pending human approval. A backend error never breaks the agent: the call is allowed and enforcement is skipped for that step.

Advanced: raw capture surfaces

init() and hook() compose lower-level pieces that remain importable for consumers that need them directly:

  • evidence_ledger.py: a local append-only audit log with integrity hashes; the hook seals one DecisionJournal per invocation.
  • otel_exporter.py: create_governance_tracer() / get_governance_tracer() build the OTLP pipeline without the rest of the SDK.
  • enforcement.py: PolicyEnforcer and its asyncio twin AsyncPolicyEnforcer are the raw decide/gate clients.

Develop

uv sync --extra strands
ruff check .
python3 tests/test_enforcement.py
python3 tests/test_init.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gentrail-0.5.1.tar.gz (189.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gentrail-0.5.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file gentrail-0.5.1.tar.gz.

File metadata

  • Download URL: gentrail-0.5.1.tar.gz
  • Upload date:
  • Size: 189.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gentrail-0.5.1.tar.gz
Algorithm Hash digest
SHA256 ca3a9f0f9cf6cffa3ea080553af592a7f02982bd932b2f4ef91655a44a4d61a3
MD5 d920c6ab82ef65c192598383e5d8da53
BLAKE2b-256 2d55b01beb7da57d015745ff95cbb412b53d142da256786cb89eea9df961d663

See more details on using hashes here.

Provenance

The following attestation bundles were made for gentrail-0.5.1.tar.gz:

Publisher: publish.yml on aigentrail/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gentrail-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: gentrail-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gentrail-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a987a4d2e27d6d45f361b1f1e5f2f590ec1395ae80adc1b79e64fc979e71e61
MD5 772d801f5c4bcb39a889c97c415c2421
BLAKE2b-256 e6708655f9cee263d4cd3337896066bc976e10463a9141f82b8323fdf219553b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gentrail-0.5.1-py3-none-any.whl:

Publisher: publish.yml on aigentrail/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 files

0.5.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page