Python client for Certiv (https://app.certiv.ai)
Project description
Certiv Python SDK
Zero-instrumentation monitoring and policy enforcement for LLM interactions. Add one line of code to monitor and control tool calls across OpenAI, Anthropic, and Google AI.
Installation
pip install certiv
Quick Start
import certiv
# Initialize with your credentials
certiv.init(
agent_id="your-agent-id",
agent_secret="your-agent-secret",
)
# Use any LLM provider normally - automatically monitored!
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "What's the weather?"}],
tools=[...]
)
That's it! All LLM interactions are now monitored and policy-enforced through the Certiv dashboard.
Features
- Zero Instrumentation - No code changes to your LLM calls. Just initialize and go.
- Policy Enforcement - Control tool/function execution with allow, block, pause for approval, or graceful blocking
- Multi-Provider Support - Works seamlessly with OpenAI, Anthropic Claude, and Google Gemini
- Remote Execution - Optionally execute sensitive functions in secure remote environments
- LangChain Integration - First-class support for LangChain agents and tools
- Real-time Monitoring - View all LLM interactions in the Certiv dashboard
- Transparent Interception - Patches HTTP transport layers (httpx, requests) without modifying your code
Supported Providers
| Provider | Status |
|---|---|
| OpenAI | ✅ Supported |
| Anthropic | ✅ Supported |
| Google AI | ✅ Supported |
Works with both direct API clients and LangChain integrations.
How It Works
Certiv operates at the HTTP transport layer:
- Automatic Interception - Patches
httpxandrequeststransport layers to intercept LLM API calls - Policy Evaluation - Sends tool calls to Certiv backend for real-time policy decisions
- Enforcement - Modifies responses based on policy (allow, block, pause, gracefully block)
- Transparent - Your application code remains unchanged
Your Code → LLM Client → [Certiv Intercept] → LLM Provider API
↓
Policy Check
↓
Your Code ← Modified Response ← Original Response
Policy Actions
Allow
Tool calls execute normally. No modifications to the response.
Block
Blocked tool calls are silently removed from the LLM response. The model doesn't see them in the execution results.
Graceful Block
Blocked tool calls are replaced with a special certiv_tool that explains the block reason to the LLM, allowing it to adapt its behavior.
Pause
Execution waits for manual approval through the Certiv dashboard (up to 5 minutes). Falls back to block on timeout or denial.
Full Example
import os
import certiv
from openai import OpenAI
# Initialize Certiv
certiv.init(
agent_id=os.getenv("CERTIV_AGENT_ID"),
agent_secret=os.getenv("CERTIV_AGENT_SECRET"),
endpoint="https://api.certiv.ai", # Optional, this is the default
debug=False, # Optional, enable debug logging
)
# Define your tools
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
},
"required": ["location"],
},
},
},
]
# Use OpenAI normally
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": "What's the weather in San Francisco?"}
],
tools=tools,
)
# Certiv automatically monitors and enforces policy
print(response.choices[0].message)
LangChain Integration
Certiv works seamlessly with LangChain:
import certiv
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain.tools import Tool
# Initialize Certiv
certiv.init(
agent_id="your-agent-id",
agent_secret="your-agent-secret",
)
# Define tools
def search(query: str) -> str:
return f"Results for: {query}"
tools = [
Tool(
name="Search",
func=search,
description="Useful for searching information",
),
]
# Create agent
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# All interactions automatically monitored
result = agent_executor.invoke({"input": "Search for Python tutorials"})
Configuration
Required Parameters
agent_id(str): Your Certiv agent ID from the dashboardagent_secret(str): Your Certiv agent secret
Optional Parameters
endpoint(str): Certiv API endpoint. Default:https://api.certiv.aidebug(bool): Enable debug logging. Default:False
Environment Variables
You can also configure via environment variables:
export CERTIV_AGENT_ID=your-agent-id
export CERTIV_AGENT_SECRET=your-agent-secret
export CERTIV_ENDPOINT=https://api.certiv.ai
import certiv
import os
certiv.init(
agent_id=os.getenv("CERTIV_AGENT_ID"),
agent_secret=os.getenv("CERTIV_AGENT_SECRET"),
)
Requirements
- Python 3.9 or higher
- Works with
httpxandrequests-based HTTP clients
Advanced Features
Remote Function Execution
Execute sensitive functions in secure remote environments:
# Define a function
def execute_database_query(query: str):
# This function can be executed remotely
return db.execute(query)
# Certiv can intercept and execute this remotely based on policy
# Configure remote execution in the Certiv dashboard
Function Hash Freezing
Prevent unauthorized modifications to frozen functions:
# Functions can be "frozen" with hash validation
# Attempts to modify frozen functions are rejected
# Configure in dashboard with override=false
Shutdown
Certiv automatically cleans up on exit, but you can manually shutdown:
import certiv
certiv.shutdown()
This restores all patched HTTP transport layers and stops background threads.
Documentation
- CLAUDE.md - Architecture and development guide
- TEST_DOCUMENTATION.md - Test suite documentation
- CHANGELOG.md - Version history
Requirements
Requires Python 3.9+. Core dependencies:
pydantic>=2.12.3- Data validationhttpx>=0.27.0- HTTP clientrequests>=2.32.5- HTTP clientpsutil>=7.1.2- Process monitoring
License
MIT License - see LICENSE for details.
Support
- Issues: GitHub Issues
- Email: support@certiv.ai
- Website: certiv.ai
Contributing
Contributions welcome! Please ensure:
- Code is formatted with
black(line length 88) - Linting passes with
ruff - Type hints validated with
mypy - Tests pass with
pytest - Copyright header included:
# Copyright (c) 2024 Certiv.ai/# SPDX-License-Identifier: MIT
See CLAUDE.md for detailed development instructions.
Project details
Release history Release notifications | RSS feed
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 certiv-3.0.2.tar.gz.
File metadata
- Download URL: certiv-3.0.2.tar.gz
- Upload date:
- Size: 88.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2f7ba7abb57a33a0e086736d6cee1f77cbe86e05270abcf8f666d7110f708fa
|
|
| MD5 |
aee2f3d8691c350697be0d2000729390
|
|
| BLAKE2b-256 |
496ec07e566364260b104fd7f02a7b5afe3b57097973b3895c63505f72febc70
|
File details
Details for the file certiv-3.0.2-py3-none-any.whl.
File metadata
- Download URL: certiv-3.0.2-py3-none-any.whl
- Upload date:
- Size: 56.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dbba5d45127d2d9b437596485f32e357b721496924cd4e6d8e71f235dde76a8
|
|
| MD5 |
cf908bf0cdfaea9e61573b3bc7d65b7c
|
|
| BLAKE2b-256 |
c4ed75c9811c32dd93c06e4df9d5ff83adb2ea5c9f351415e0f9e79250ae2bc2
|