Metadata-Version: 2.4
Name: driftgard
Version: 1.29.1
Summary: Official DriftGard Python SDK — evaluate LLM interactions against your compliance policy
Author-email: Driftgard <support@driftgard.com>
License: MIT
Project-URL: Homepage, https://driftgard.com
Project-URL: Repository, https://github.com/driftgard/driftgard-sdk-python
Keywords: driftgard,ai,compliance,guardrails,llm,evaluation,policy,audit
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.20.0

# driftgard

Official Python SDK for [DriftGard](https://driftgard.com).

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

```bash
pip install driftgard
```

Requires Python 3.8 or newer.

## Quick Start

```python
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.

```python
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:

```python
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`.

```python
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.

```python
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

- [Gateway](docs/gateway.md)
- [Tool calls](docs/tool-calls.md)
- [Local evaluation](docs/local-evaluation.md)
- [Governed Knowledge](docs/knowledge.md)
- [Configuration and failure modes](docs/configuration.md)
- [Framework integrations](docs/integrations.md)

## Requirements

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

## License

MIT

