Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                

Cookbook

Short recipes for the whitecircle Python SDK. Every snippet uses the real API; concepts and the HTTP reference live at https://whitecircle.com/docs.

Read this in two minutes

  1. Skim "The model" below: it is everything the SDK assumes you know.
  2. Read Getting started for configuration and how to read a result.
  3. Jump to the page for your task in the table. Pages are independent.
  4. If a check returns no verdict (result.checked is False), read Metadata and Conditions.
PageTask
Getting startedConfigure the client, run a first check, read the result
Metadata and ConditionsChoose which Policies run; debug "no verdict"
Inline PoliciesSend a Policy's rules with the check, then reference it by external_id
Context and resetsConversations, Event.reset(), backfilling history
Agents and toolsTool calls, agent steps, parents and links, the run graph
Streaming repliesShow only checked text while the model generates it
ImagesCheck standalone images and images inside a conversation
Managing PoliciesCreate Policies, Metrics and Conditions; shadow mode to production
Strikes and webhooksUser risk, strikes, appeals, user properties, verifying webhooks
UsageRead billed usage and cost per Event type (client.billing.usage())
Errors and testingExceptions, retries, timeouts, logging, testing your code
Recipe: support chatbotAll of the above in one async integration

The model

  • You send Events: a user message, an assistant reply, a tool call, an agent step, an image.
  • Each Event belongs to an Environment (environment_id, required on every Events call).
  • Active Conditions on that Environment match the Event's metadata and select Policies. No match, no Policies, no verdict.
  • You get result.flagged, a result per Policy in result.policies, and result.checked to tell "passed" from "not checked".
  • Events with the same external_session_id form a conversation: earlier Events are context for later ones.

Python

from whitecircle import Event, WhiteCircle

client = WhiteCircle()  # WHITECIRCLE_API_KEY, WHITECIRCLE_ENVIRONMENT_ID

result = client.events.check(
    Event.user("Can you prescribe antibiotics?", metadata={"app": "pharmacy-bot"}),
    external_session_id="conversation_456",
)
print(result.checked, result.flagged, result.note)

Source on GitHub