Skip to main content

Python client for Certiv (https://app.certiv.ai)

Project description

Certiv Python SDK

PyPI version Python Version License: MIT

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:

  1. Automatic Interception - Patches httpx and requests transport layers to intercept LLM API calls
  2. Policy Evaluation - Sends tool calls to Certiv backend for real-time policy decisions
  3. Enforcement - Modifies responses based on policy (allow, block, pause, gracefully block)
  4. 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 dashboard
  • agent_secret (str): Your Certiv agent secret

Optional Parameters

  • endpoint (str): Certiv API endpoint. Default: https://api.certiv.ai
  • debug (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 httpx and requests-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

Requirements

Requires Python 3.9+. Core dependencies:

  • pydantic>=2.12.3 - Data validation
  • httpx>=0.27.0 - HTTP client
  • requests>=2.32.5 - HTTP client
  • psutil>=7.1.2 - Process monitoring

License

MIT License - see LICENSE for details.

Support

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


Download files

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

Source Distribution

certiv-3.0.2.tar.gz (88.5 kB view details)

Uploaded Source

Built Distribution

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

certiv-3.0.2-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

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

Hashes for certiv-3.0.2.tar.gz
Algorithm Hash digest
SHA256 b2f7ba7abb57a33a0e086736d6cee1f77cbe86e05270abcf8f666d7110f708fa
MD5 aee2f3d8691c350697be0d2000729390
BLAKE2b-256 496ec07e566364260b104fd7f02a7b5afe3b57097973b3895c63505f72febc70

See more details on using hashes here.

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

Hashes for certiv-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6dbba5d45127d2d9b437596485f32e357b721496924cd4e6d8e71f235dde76a8
MD5 cf908bf0cdfaea9e61573b3bc7d65b7c
BLAKE2b-256 c4ed75c9811c32dd93c06e4df9d5ff83adb2ea5c9f351415e0f9e79250ae2bc2

See more details on using hashes here.

Supported by

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