Python SDK for Verdic Guard execution validation
Project description
Verdic Guard Python SDK
A minimal Python SDK for validating outputs against execution contracts using the Verdic Guard API.
Installation
Using pip
pip install verdic-guard
From source
git clone https://github.com/verdic/verdic-guard-python.git
cd verdic-guard-python
pip install -r requirements.txt
python setup.py install
Or copy verdic_guard.py directly into your project (only requires requests library).
New to Verdic Guard?
📚 Read the Quickstart Guide for a complete introduction to Verdic Guard and execution contracts.
Quick Start
from verdic_guard import validate
# Define your execution contract
execution_config = {
"schemaVersion": "1.0.0",
"globalIntent": "Provide medical information",
"taskIntent": "Explain medication side effects",
"stepIntent": "List common side effects",
"domain": "medicine",
"audience": "general_public",
"allowCode": False,
"allowExplanation": True,
"allowActionableDetails": False,
"executionThreshold": 0.3
}
# Validate an output
output = "Common side effects include nausea and headache."
try:
result = validate(
api_url="https://verdic.dev",
execution_config=execution_config,
output=output
)
if result["status"] == "OK":
print("✓ Output validated successfully")
print(f" Drift: {result['drift']}")
elif result["status"] == "BLOCKED":
print(f"✗ Output blocked: {result['reason']}")
print(f" Detail: {result['detail']}")
if "hint" in result:
print(f" Hint: {result['hint']}")
elif result["status"] == "FAILED":
print(f"✗ Validation failed: {result['message']}")
except Exception as e:
print(f"Error: {e}")
API Reference
validate(api_url, execution_config, output)
Validates an output against an execution contract.
Parameters:
api_url(str): The Verdic Guard API URL (e.g., "https://verdic.dev")execution_config(dict): Execution contract dictionary containing validation rulesoutput(str): The output string to validate
Returns:
A dictionary with one of the following structures:
Success (OK):
{
"status": "OK",
"drift": 0.15, # float between 0 and 1
"output": "validated output string"
}
Blocked:
{
"status": "BLOCKED",
"reason": "MODALITY", # or "DOMAIN_SAFETY" or "INTENT_DRIFT"
"detail": "Detailed explanation of the violation",
"hint": "Optional suggestion for remediation"
}
Failed:
{
"status": "FAILED",
"message": "Error description"
}
Raises:
requests.RequestException: If a network error occursrequests.HTTPError: If the API returns an HTTP error status
ExecutionConfig Schema
The execution_config parameter should be a dictionary with the following structure:
{
"schemaVersion": "1.0.0", # Required: Schema version
# Intent hierarchy (all required)
"globalIntent": "High-level purpose",
"taskIntent": "Specific task being performed",
"stepIntent": "Current step within the task",
# Context (required)
"domain": "software", # software, medicine, chemistry, law, finance, education, general
"audience": "professional", # general_public, student, professional, researcher
# Modality controls (optional, defaults shown)
"allowCode": True, # Whether code blocks are permitted
"allowExplanation": True, # Whether explanatory text is permitted
"allowCreative": False, # Whether creative/narrative content is permitted
"allowActionableDetails": False, # Whether domain-specific actionable details are permitted
# Drift control (optional)
"executionThreshold": 0.5, # Drift threshold (0-1) above which output is blocked
# Retry control (optional)
"maxRetries": 0 # Maximum retry attempts (informational only)
}
Examples
Software Development
from verdic_guard import validate
result = validate(
api_url="https://verdic.dev",
execution_config={
"schemaVersion": "1.0.0",
"globalIntent": "Provide software development assistance",
"taskIntent": "Generate API endpoint code",
"stepIntent": "Create Express route handler",
"domain": "software",
"audience": "professional",
"allowCode": True,
"allowExplanation": True,
"executionThreshold": 0.5
},
output="const handler = (req, res) => { res.json({ status: 'ok' }); }"
)
Medical Information
from verdic_guard import validate
result = validate(
api_url="https://verdic.dev",
execution_config={
"schemaVersion": "1.0.0",
"globalIntent": "Provide medical information",
"taskIntent": "Explain medication side effects",
"stepIntent": "List common side effects",
"domain": "medicine",
"audience": "general_public",
"allowCode": False,
"allowExplanation": True,
"allowActionableDetails": False,
"executionThreshold": 0.3
},
output="Common side effects include nausea and headache."
)
Error Handling
The SDK raises standard requests library exceptions:
from verdic_guard import validate
import requests
try:
result = validate(api_url, execution_config, output)
except requests.ConnectionError:
print("Network connection error")
except requests.Timeout:
print("Request timed out")
except requests.HTTPError as e:
print(f"HTTP error: {e.response.status_code}")
except requests.RequestException as e:
print(f"Request error: {e}")
License
MIT License - see LICENSE file for details
Support
For issues and questions:
- GitHub Issues: https://github.com/verdic/verdic-guard-python/issues
- Documentation: https://verdic.dev/docs
- Email: support@verdic.dev
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 verdic_guard-1.0.0.tar.gz.
File metadata
- Download URL: verdic_guard-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c798d9887fb068db7e227c8b8a8d8233c7c569e0e97fc94722824087f27ac878
|
|
| MD5 |
857499c445e79bb9466d423edb0324f7
|
|
| BLAKE2b-256 |
a3ce05522e193040e8e1fef6f7b9e2a305d3d9d10d3f9a8449a43026c213bbe9
|
File details
Details for the file verdic_guard-1.0.0-py3-none-any.whl.
File metadata
- Download URL: verdic_guard-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3819d890fe2a13b98b82faa66b13f0d98390642b73cd77d2cccd463e661ffb79
|
|
| MD5 |
ab3d9a7ce12bdd1248daffb78c11adfb
|
|
| BLAKE2b-256 |
09397c252fe94b92586acc82f0c9de2acc7efae2ac944333cea9e40133b44dad
|