pydantic-ai-deepkeep
DeepKeep AI Firewall custom guardrails for Pydantic AI.
This package follows Pydantic AI's native custom capability extension point. Add DeepKeepGuardrail to an Agent with capabilities=[...] to check input before a model request and output after a model response.
Installation
pip install pydantic-ai-deepkeep
Set credentials:
export DEEPKEEP_API_KEY="dk_..."
export DEEPKEEP_BASE_URL="https://api.example.deepkeep.ai"
Input and output guardrails
from pydantic_ai import Agent
from pydantic_ai_deepkeep import DeepKeepGuardrail
agent = Agent(
"openai:gpt-5.2",
instructions="Answer user questions safely and concisely.",
capabilities=[
DeepKeepGuardrail(
pre_model="input-firewall-id",
post_model="output-firewall-id",
)
],
)
result = agent.run_sync("Explain how to store API keys securely.")
print(result.output)
Agent specs
DeepKeepGuardrail supports Pydantic AI agent specs when registered as a custom capability type:
model: openai:gpt-5.2
instructions: Answer user questions safely and concisely.
capabilities:
- DeepKeepGuardrail:
pre_model: input-firewall-id
post_model: output-firewall-id
from pydantic_ai import Agent
from pydantic_ai_deepkeep import DeepKeepGuardrail
agent = Agent.from_file("agent.yaml", custom_capability_types=[DeepKeepGuardrail])
Why a capability
Pydantic AI capabilities bundle hooks, tools, instructions, and settings. DeepKeep should run deterministically around model execution, so the correct integration surface is a custom AbstractCapability, not an agent-callable tool.
DeepKeepGuardrail uses:
before_model_requestfor DeepKeep pre-moderation before content reaches the model.after_model_requestfor DeepKeep post-moderation before model output is returned.
DeepKeep endpoints
This package uses the same DeepKeep OpenAI-compatible moderation endpoints as the other DeepKeep integrations:
POST /api/v3/openai/moderations/prewith{"model", "input", "title", "chat"}.POST /api/v3/openai/moderations/postwith{"model", "output", "title", "chat"}.X-API-Keyfor authentication.
pre_model and post_model are DeepKeep firewall IDs. Each value is sent to the matching moderation endpoint as the model field.
Guardrail actions
DeepKeep responses are interpreted from verbosity[].details.guardrail_action:
block: RaisesDeepKeepBlockedErrorand aborts the run.redactormodify: Replaces the latest text message or response part when DeepKeep returns modified content.alert: Allows the run to continue.
If DeepKeep returns an unsupported action, the capability fails closed.
Configuration
api_key: DeepKeep API key. If omitted, readsDEEPKEEP_API_KEY.base_url: DeepKeep base URL, without a trailing slash. If omitted, readsDEEPKEEP_BASE_URL.pre_model: DeepKeep firewall ID for pre-moderation.post_model: DeepKeep firewall ID for post-moderation.title: Optional title value sent to DeepKeep.chat: Optional chat value sent to DeepKeep.timeout: Request timeout in seconds. Defaults to30.0.fail_closed: Raise when DeepKeep cannot be reached. Defaults toTrue.
Recommended Pydantic AI docs positioning
Position the public integration as DeepKeep AI Firewall in Pydantic AI's integrations or custom capabilities area:
DeepKeep AI Firewall
Use DeepKeep AI Firewall as a custom Pydantic AI capability to enforce runtime guardrails before model requests and after model responses. Supports allow, block, redact, modify, and alert workflows for prompt injection, jailbreaks, sensitive data leakage, unsafe content, and other AI risks.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_deepkeep-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_deepkeep-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d49ded72986d2280a4f94c8a1e2990b8fdc231e80697c324b3623b502e13e2f
|
|
| MD5 |
fb7c16e6c95946a725ff0742d99709ab
|
|
| BLAKE2b-256 |
0adcf01c2657b1b747ecd323c80418e7fa1f87cc7842f55957d04beecdfb420f
|
File details
Details for the file pydantic_ai_deepkeep-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_deepkeep-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5fdb62e98d5909efa5d2b4b41051f5bee7dbe3e089e5ce2669af7addb9a2516
|
|
| MD5 |
bab359163495dcb59918e96717a281cc
|
|
| BLAKE2b-256 |
9b1ae0e99138239f2e9c03229f06d8400b6d0a30058c32b5a41c39d253ed5c18
|