Skip to main content

driftgard

Official Python SDK for DriftGard.

Use it to control what production AI can say and do: evaluate prompts and responses, run OpenAI-compatible gateway calls through DriftGard, validate agent tool calls, and record audit evidence.

Install

pip install driftgard

Requires Python 3.8 or newer.

Quick Start

from driftgard import Driftgard

dg = Driftgard(api_key="dg_...")

result = dg.evaluate(
    project_id="proj_...",
    prompt="What stocks should I buy?",
    response="You should invest everything in...",
    model_id="gpt-4o",
)

if not result["evaluation"]["allowed"]:
    print("Blocked:", result.get("fallback", {}).get("message"))
elif result["evaluation"].get("sanitized"):
    print("Use sanitized response:", result["evaluation"]["sanitized_response"])
else:
    print("Allowed")

Inline Gateway

Use the gateway when DriftGard should sit in the request path, call the provider, enforce policy, and return the final response.

completion = dg.gateway_chat_completions(
    project_id="proj_...",
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a support assistant."},
        {"role": "user", "content": "Summarize the refund process."},
    ],
    driftgard={
        "gateway_mode": "enforce",
        "agent_id": "support-agent",
        "agent_role": "customer_support",
        "session_id": "sess_123",
    },
)

print(completion["choices"][0]["message"]["content"])
print(completion.get("driftgard", {}).get("gateway_decision"))

Streaming is also supported:

stream = dg.stream_gateway_chat_completions(
    project_id="proj_...",
    model="gpt-4o-mini",
    messages=messages,
    driftgard={"gateway_mode": "observe"},
)

Tool Call Validation

Validate agent tool calls against Control Pack tool_rules.

result = dg.evaluate(
    project_id="proj_...",
    eval_mode="tool_call",
    tool_call={
        "tool_name": "transfer_money",
        "parameters": {"amount": 500, "to_account": "acct_123"},
    },
    agent_role="payments_agent",
    model_id="agent-runtime",
)

if not result["evaluation"]["allowed"]:
    raise RuntimeError(result.get("fallback", {}).get("message", "Tool call blocked"))

Local Evaluation

For sensitive environments, the SDK can evaluate locally through DriftGard's WASM evaluator.

dg = Driftgard(
    api_key="dg_...",
    mode="local",
    project_id="proj_...",
)

dg.init()
result = dg.evaluate(prompt=prompt, response=response, model_id="local-model")

Modes:

Mode Behavior
remote Send prompt/response to DriftGard API
local Evaluate locally; no prompt/response leaves your environment
local-with-audit Evaluate locally and report verdict metadata only

Framework Integrations

Included integrations:

  • LangChain response guardrail
  • LangChain tool guard
  • CrewAI response and tool guardrails
  • Strands / AWS Agent Core hook
  • local semantic matching for local mode

Documentation

Requirements

  • Python 3.8+
  • DriftGard API key
  • DriftGard project ID

License

MIT

Download files

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

Source Distribution

driftgard-1.29.1.tar.gz (500.3 kB view details)

Uploaded Source

Built Distribution

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

driftgard-1.29.1-py3-none-any.whl (491.0 kB view details)

Uploaded Python 3

File details

Details for the file driftgard-1.29.1.tar.gz.

File metadata

  • Download URL: driftgard-1.29.1.tar.gz
  • Upload date:
  • Size: 500.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for driftgard-1.29.1.tar.gz
Algorithm Hash digest
SHA256 e17209de39b2cf1f041463c26fbe9422b2c80f8c948c9b52965abee6d8352e95
MD5 eb6f84449c68414caa7124b8f61aa0b7
BLAKE2b-256 aa78f2b985d19d152437a34f4338b5fb31b1c6192a8da50230770dd5af1af4ff

See more details on using hashes here.

File details

Details for the file driftgard-1.29.1-py3-none-any.whl.

File metadata

  • Download URL: driftgard-1.29.1-py3-none-any.whl
  • Upload date:
  • Size: 491.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for driftgard-1.29.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16dcc8dd5fd7b696edfcb7a46dcd9d8b9827eae12fa1e4e0c1e84a470985f9b6
MD5 5d7abb7eb945b3eb878b724f99ff92d0
BLAKE2b-256 3fa5ef445e0077ebc0f9ef771f8491f13383ffca96d35eaca9e65f05a3fe7b3b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.29.1 This release

2 files

1.29.0

2 files

1.28.0

2 files

1.27.2

2 files

1.27.1

2 files

1.27.0

2 files

1.26.0

2 files

1.25.1

2 files

1.25.0

2 files

1.24.0

2 files

1.23.0

2 files

1.22.0

2 files

1.21.0

2 files

1.20.0

2 files

1.19.0

2 files

1.18.0

2 files

1.17.0

2 files

1.16.0

2 files

1.15.0

2 files

1.14.0

2 files

1.13.0

2 files

1.12.0

2 files

1.11.0

2 files

1.10.0

2 files

1.9.0

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page