Skip to main content

Python SDK

The wonderfence-sdk package wraps the Alice evaluate API. Every call returns an action (BLOCK, MASK, DETECT or NO_ACTION), the masked or block text, and the detections that fired, so your code decides what to do next.

Status: Generally available · Evaluates: Prompts, Responses · Vendor: Alice

User prompts, model responses and images. Session and user ids ride along for tracing.

Setup​

pip install wonderfence-sdk

Configuration: ALICE_API_KEY, app_id

Example​

from wonderfence_sdk.client import WonderFenceV2Client
from wonderfence_sdk.models import AnalysisContext

client = WonderFenceV2Client(api_key="your_api_key")

context = AnalysisContext(session_id="session_id", user_id="user_id")
app_id = "your-app-uuid"

# Synchronous
result = client.evaluate_prompt_sync(app_id=app_id, context=context, prompt="Your prompt text")
result = client.evaluate_response_sync(app_id=app_id, context=context, response="Response text")

# Asynchronous
result = await client.evaluate_prompt(app_id=app_id, context=context, prompt="Your prompt text")
result = await client.evaluate_response(app_id=app_id, context=context, response="Response text")

tool calls and tool results

import json

# Synchronous
result = client.evaluate_tool_call_sync(
app_id=app_id,
context=context,
tool_call=json.dumps({"city": "Paris"}),
tool_name="get_weather",
tool_call_id="call_123",
mcp_server="weather-server",
)
result = client.evaluate_tool_result_sync(
app_id=app_id,
context=context,
tool_result="18°C and sunny",
tool_name="get_weather",
tool_call_id="call_123",
)

# Asynchronous
result = await client.evaluate_tool_call(app_id=app_id, context=context, tool_call=json.dumps({"city": "Paris"}))
result = await client.evaluate_tool_result(app_id=app_id, context=context, tool_result="18°C and sunny")

Good to know​

The app_id comes from your Application Inventory and selects which policies apply. Text and image inputs are mutually exclusive per call.

The tool methods (evaluate_tool_call and evaluate_tool_result, with _sync variants) need wonderfence-sdk 3.1.0 or later, and WONDER_FENCE_AGENTIC_MESSAGE_TYPES enabled on your Alice project until tool message types are generally available. Without it the API answers 400, which the SDK raises without retrying. tool_name and tool_call_id are optional; tool_call_id pairs a call with its result. The optional mcp_server (3.2.0 or later) names the MCP server the tool belongs to, as your client knows it, and is stored with the call or result so you can audit and filter tool traffic by server. Left out, it is read from a tool named in Claude Code's mcp__<server>__<tool> form. Pass tool arguments as a string (json.dumps them). Tool calls and results are matched only against policies that list the Tool Call / Tool Result message types; a policy that lists only Prompt or Response does not screen them. Text is limited to 10,240 characters and an empty string is rejected, both with a 400, so truncate or chunk large tool output before evaluating it.