Skip to main content

Norcaster — Python SDK

Thin wrapper around the Norcaster REST API for deploy, run, status, and usage.

Installation

pip install norcaster

Python 3.10 or later. The SDK's only dependency is httpx.

Command line

The norcaster command comes with the cli extra, which adds typer, rich and python-dotenv:

pip install "norcaster[cli]"
export NORCASTER_API_KEY="<your-api-key>"
norcaster deploy qx-example
norcaster run <deployment_id> -i '{"prompt": "Hello!"}'

Without the extra, norcaster only says how to install it. The CLI reads NORCASTER_API_KEY and NORCASTER_API_URL from the shell first, then from .env in the current folder, then from ~/.norcaster.env; it never reads .env files in parent folders. norcaster --help lists the commands.

Usage

from norcaster import NorcasterCloudClient

client = NorcasterCloudClient(api_key="your-api-key")

# Deploy a model
deploy = client.deploy("my-llama-7b", model_path="models/user/llama")
print(deploy.deployment_id, deploy.status)

# Run inference
run = client.run(deploy.deployment_id, {"prompt": "Hello"})
print(run.job_id, run.status)

# Check status
status = client.status(run.job_id)
print(status.status, status.output_data)

# Get usage
usage = client.usage()
print(usage.tokens_used, usage.compute_seconds)

Response types

  • DeployResult — deployment_id, status, message
  • RunResult — job_id, status, message
  • StatusResult — id, type, status, output_data, tokens_used, etc.
  • UsageResult — user_id, tokens_used, compute_seconds, job_count
  • CheckResult — decision, receipt, prompt or messages (when the decision is hide), code, reason
  • CheckReceipt — id, content_sha256, policy_version, decided_at

Check before your app calls an AI provider

Your app can ask Norcaster for a decision and then call the AI provider itself. Norcaster answers allow, hide or block from the app's rules, and keeps a record of every answer.

What the record shows: the app asked Norcaster before it called the provider. Norcaster does not see the provider call, so the record does not show what the app sent afterwards.

Ask for a decision

from norcaster import NorcasterCloudClient

client = NorcasterCloudClient(api_key="your-api-key")

prompt = "Summarise this ticket for the customer"
result = client.check(prompt)  # or client.check(messages=[...]) for a conversation

if result.decision == "block":
    ...  # do not send it; result.reason says why
elif result.decision == "hide":
    prompt = result.prompt  # send this version: the sensitive data is hidden

receipt = result.receipt
print(receipt.id)              # the record in Norcaster
print(receipt.content_sha256)  # SHA-256 of what you asked about
print(receipt.policy_version)  # the version of the app's rules that decided
print(receipt.decided_at)      # when
  • Pass prompt or messages, not both. When you ask with messages, a hide answer comes back in result.messages.
  • deployment_id="..." is the app's id. Leave it out when the key belongs to one app.
  • The key needs the runs:write scope.
  • In an async app, use await client.acheck(...).
  • content_sha256(prompt) or content_sha256(messages=...) gives the hash for what you are about to send, to compare with the receipt.

Wrap your OpenAI or Anthropic client

from openai import OpenAI
from norcaster import NorcasterBlocked, norcaster_check

openai_client = client.wrap_openai(OpenAI())

try:
    answer = openai_client.chat.completions.create(model="gpt-4o-mini", messages=messages)
except NorcasterBlocked as blocked:
    print(blocked.code, blocked.receipt_id)   # the provider was not called
else:
    print(norcaster_check(answer).receipt_id)  # the record behind this answer

Before each call the wrapper asks Norcaster:

  • allow: the request goes to the provider as it is.
  • hide: the wrapper sends the version Norcaster returned, with the sensitive data hidden.
  • block: the provider is not called and NorcasterBlocked is raised. The error names the decision, the reason and the receipt.

client.wrap_anthropic(Anthropic()) does the same for messages.create. AsyncOpenAI and AsyncAnthropic clients work the same way with await. You pass in your own client: this SDK does not install or import openai or anthropic.

What is covered:

  • OpenAI: chat.completions.create and responses.create (the Responses API), streamed or not. See OpenAI's Responses API for what a Responses call adds.
  • Anthropic: messages.create, streamed or not.
  • Their parse and stream helpers: see The provider's parse and stream helpers.
  • Amazon Bedrock's Converse API, on your boto3 client: see Amazon Bedrock (Converse).
  • Google Gemini, on your google-genai client: see Google Gemini.
  • Which client libraries these work on, Azure OpenAI and Claude on Bedrock or Vertex AI included: see Covered client libraries and methods.
  • Any other call on the wrapped client raises an error. Make that call on your own client, where it is not checked.
  • The check is of what your app sends. The provider's answer is not checked unless you turn that on (Check the model's answer too).
  • Images, files and audio: see Images, files and audio.
  • In an Anthropic conversation, the model's signed thinking is left out of the check and sent on unchanged.
  • A request that also puts its content in extra_body is not sent: messages there (OpenAI), or messages or system (Anthropic). The client would send that in place of what was checked. Other keys in extra_body are sent as they are.
  • An OpenAI chat request with a predicted output (prediction, also inside extra_body) is not sent. OpenAI gets its text, usually the same file a message holds, and a check doesn't read it, so a hide in that file would go out unhidden there. Leave prediction out of checked calls.
  • An Azure OpenAI chat request with data_sources in extra_body (Azure OpenAI On Your Data) is not sent: Azure fetches documents from your index into the prompt, and a check never reads them.

Covered client libraries and methods

Your client Wrap it with Checked
openai: OpenAI, AsyncOpenAI wrap_openai chat.completions.create, .parse, .stream; responses.create, .parse, .stream
openai: AzureOpenAI, AsyncAzureOpenAI (Azure OpenAI) wrap_openai the same, on your deployments
anthropic: Anthropic, AsyncAnthropic wrap_anthropic messages.create, .parse, .stream
anthropic: AnthropicBedrock, AsyncAnthropicBedrock (Claude on Amazon Bedrock) wrap_anthropic the same
anthropic: AnthropicVertex, AsyncAnthropicVertex (Claude on Google Vertex AI) wrap_anthropic the same
boto3: boto3.client("bedrock-runtime"); aioboto3 and aiobotocore's wrap_bedrock converse, converse_stream
google-genai: genai.Client (the Gemini API and Vertex AI) wrap_gemini models.generate_content, models.generate_content_stream, and chats (chats.create, then send_message, send_message_stream); the same on aio

Everything else on a wrapped client raises and names what it is, so a call Norcaster doesn't check is never made through the wrapper by accident. Not covered yet: Bedrock's invoke_model and invoke_model_with_response_stream (for Claude, wrap an AnthropicBedrock client instead). Check those calls yourself with client.check(...).

Tried with openai 2.26.0, anthropic 1.11.0, boto3 1.43.87 and google-genai 3.0.0, each on a stubbed transport, google-genai 2.34.0 and 3.6.1 too, and the async Bedrock client with aiobotocore 3.10.0 against a local stand-in for Bedrock.

Images, files and audio

A request can hold images, documents (PDF, Word, text files) and audio: OpenAI chat image_url, file and input_audio; Anthropic image and document (inline, by URL, from the Files API, or inside a tool result); and in the Responses API input_image, input_file, input_audio, computer screenshots, an earlier generated image sent back, and the files a request gives its tools.

They meet your app's rules for them, the same rules the Norcaster gateway applies: allow, warn, block, or "scan required" (which blocks, since nothing reads them), and limits on how many, how large, how many pixels and which media types. With no rules set, they are allowed.

Norcaster never gets the file. For each inline one the wrapper sends a description in its place: the SHA-256 of its bytes, their size, the media type its first bytes show, and an image's width and height (describe_media). URLs and file ids are sent as they are. The provider gets your request unchanged, or, on hide, with the hidden text and the same files: a hide never changes a file, and a hidden version that would is not sent.

What a check of such a request shows: the app asked Norcaster, and described these files. It does not show what an image or a document says, and it does not show that the files sent were the ones described. The record lists each one as not read (contextual.not_read), and its hash (form messages_with_media) covers each file's SHA-256, so a file can be compared with it later.

client.check(messages=..., format=...) does the same for your own calls: format is "openai_chat", "anthropic_messages" or "openai_responses", and tool_files names the files a Responses request's tools are given. content_sha256(messages=..., format=...) gives the hash a receipt carries for it. A Norcaster or check engine from before 19 November 2026 refuses such a check (NorcasterCheckRefused, HTTP 400); text-only requests are sent as before.

Answers that hold an image or audio are still withheld with check_output=True (next section).

Check the model's answer too

This is off unless you turn it on. With check_output=True the wrapper also asks Norcaster about the answer before your app gets it: its text, and the tool calls it asks for (each tool's name and its arguments). Your app gets the tool calls only after that, so before any tool runs:

from norcaster import NorcasterBlocked, norcaster_output_check

openai_client = client.wrap_openai(OpenAI(), check_output=True)

try:
    answer = openai_client.chat.completions.create(model="gpt-4o-mini", messages=messages)
except NorcasterBlocked as blocked:
    if blocked.about == "answer":
        ...  # the provider answered and the answer was withheld; blocked.receipt_id names the record
    else:
        ...  # the request was blocked and the provider was not called
else:
    print(norcaster_output_check(answer).receipt_id)  # the record of the answer's check
  • allow: your app gets the answer as it is.
  • hide: your app gets the answer with the sensitive data hidden, in its text and in each tool call's arguments. The arguments stay JSON of the same shape (the same keys and value types), and the tool's name never changes. A placeholder can change what a tool does: a mail tool would get [REDACTED: EMAIL] as the address. If your tool can't run with a placeholder, treat hide as block.
  • block: NorcasterBlocked is raised with about == "answer". Your app gets nothing from that answer, its tool calls included, so it has none of them to run. The error names the decision, the reason and the receipt.

The answer's check is recorded under the same request as the check before the call, so your records show one call with two decisions. It adds one more round trip to Norcaster per call.

Know these limits before you turn it on:

  • The app's rules must cover answers. If they don't, Norcaster refuses the check (NorcasterCheckRefused, code output_rules_off) and the answer is withheld.
  • Read: the answer's text, OpenAI function calls (tool_calls and the older function_call), and Anthropic tool_use blocks. An answer with tool calls and no text is asked about too. One with neither is not, and norcaster_output_check returns None for it.
  • Not read: tools the provider runs itself (Anthropic's server_tool_use, such as web search: they ran before the answer arrived), images, reasoning, and the tool definitions you send.
  • A tool call a check can't read (an OpenAI custom tool, say) is withheld: NorcasterCannotCheck with about == "answer". So is an answer whose hidden version can't be written back into the provider's result.
  • The check engine in your own network reads tool calls too. An older engine refuses them (409 tool_calls_not_on_engine), and the answer is withheld.
  • More than one answer per call (n above 1) raises NorcasterCannotCheck before anything is sent.
  • An answer in audio raises NorcasterCannotCheck before anything is sent: modalities with anything but "text", or an audio parameter, also inside extra_body. Its transcript would not be read. An answer that comes back in audio anyway (something between your app and the model asked for it) is withheld: NorcasterCannotCheck with about == "answer".
  • A streamed answer is held until it has been checked, so your app gets its first chunk later (next section).
  • When Norcaster can't be reached after the provider answered, the answer is withheld: NorcasterUnreachable with about == "answer". With when_unreachable="let_through" your app gets the answer, and it is recorded as let through without a check, with the request it belongs to.
  • When the request itself was let through without a check, its answer is not asked about. The one let-through record stands for the call.
  • The record shows your app asked about a text and tool calls, and names the tools (never their arguments). It does not show that they were the provider's answer, or what your app did afterwards: which tools it ran.

Streamed answers

With check_output=True a streamed call (stream=True) works, but your app gets nothing until the whole answer has been checked. Nothing is checked while it streams:

  1. The wrapper reads the provider's whole stream. Your app gets none of it yet.
  2. It asks Norcaster once, about the whole answer's text and its tool calls (each one put together from its pieces), under the request's check.
  3. Only then does create return. allow: you get the provider's chunks as they came. hide: the same chunks, with Norcaster's text where the answer's text starts and the later pieces of text empty, and each tool call's hidden arguments in its first piece, its later pieces empty. block: NorcasterBlocked (about == "answer") is raised from create, and your app gets no chunk at all.

What it costs: the wait for the first chunk becomes the time the provider takes to finish the whole answer, plus one round trip to Norcaster. An app that streams so that people see the first words early loses that while answer checks are on.

stream = openai_client.chat.completions.create(model="gpt-4o-mini", messages=messages, stream=True)
for chunk in stream:  # the provider's own chunk type
    ...
print(norcaster_output_check(stream).receipt_id)
  • You get a CheckedStream (an AsyncCheckedStream from an async client): iterate it once, use it in with, close() it. Anything else, such as response, is the provider's stream's own.
  • If the provider's stream fails part-way, its error is raised from create and none of the text before it reaches your app. No answer check is made.
  • If your app cancels the call while the answer is held, the provider's stream is closed and nothing reaches your app.
  • The whole answer is read before your app sees any of it, so stopping early (leaving the loop) does not stop the provider part-way. The record is of the whole answer.
  • Refusal text, reasoning and usage chunks are passed on as they came and are not read, as for an answer that is not streamed. A hidden answer's token list (logprobs) is set to None, because it spells out the original text.
  • A streamed tool call whose pieces can't be put together (a piece with no index, a name or id that changes on the way) is withheld.
  • When the request itself was let through without a check, its stream is not held: it reaches your app as it arrives, and its answer is not asked about.

To ask about an answer yourself, pass the request_id of the check you made before the call:

asked = client.check(messages=messages)
...  # call the provider
answer = client.check(output=text, request_id=asked.request_id)
if answer.decision == "hide":
    text = answer.output

With tool calls, send each one's name and its arguments as the JSON text the model wrote, with the text or without it:

answer = client.check(
    tool_calls=[{"name": "send_mail", "arguments": '{"to": "anna@example.com"}'}],
    request_id=asked.request_id,
)
if answer.decision == "block":
    ...  # don't run the tools
elif answer.decision == "hide":
    calls = answer.tool_calls  # the same calls, in order, with the sensitive values hidden

OpenAI's Responses API

responses.create on the wrapped client is checked the same way: before the call, and, with check_output=True, the answer before your app gets it, streamed or not.

openai_client = client.wrap_openai(OpenAI(), check_output=True)

answer = openai_client.responses.create(
    model="gpt-5-mini", instructions="Answer briefly.", input="Which branch are we on?"
)
print(answer.output_text, norcaster_check(answer).receipt_id, norcaster_output_check(answer).receipt_id)

What is checked before the call is read as the Norcaster gateway reads a Responses request: instructions first, then each item of input (a string is one user message) in its own shape, earlier function_call and function_call_output items included. On hide the hidden version goes back into the same places: instructions, each item, or the string. An earlier reasoning item is read without its encrypted state and sent back exactly as it was; a hide that would change its text means the request is not sent.

State OpenAI keeps is not part of the request, so a check does not read it:

  • With previous_response_id, conversation or an item_reference, OpenAI adds earlier turns it holds. They are not sent again, so they are not checked again. They were checked when your app sent them through the wrapper. Anything added another way (the Conversations API on your own client, a response made without the wrapper) never was.
  • With store (OpenAI's default), OpenAI keeps the model's original answer, even when Norcaster hid part of it from your app. A conversation you continue gives the model that original.

The answer's check reads output_text (the text parts of the answer's messages, run together, so the receipt's hash is the SHA-256 of answer.output_text) and its function_call items, each function's name (with its namespace, as crm.lookup) and its arguments. On hide Norcaster's text goes where the answer's text starts and the other text parts are emptied; those parts lose their annotations and logprobs, which point into or spell out the original. Each function call gets its hidden arguments. A streamed answer is held and checked once, as for chat, and the hidden version is written into every copy the stream carries: the text and argument pieces, the .done events, the finished parts and items, and the response the stream ends with. Citation events for the hidden text are not handed on.

Not sent, before anything goes to OpenAI (NorcasterCannotCheck):

  • A prompt stored at OpenAI (the prompt parameter): its template can add instructions, messages and tools a check never sees.
  • input, instructions or prompt in extra_body, where a check doesn't read them.
  • With check_output=True: a background response (background=True, its answer is fetched later with retrieve, outside the wrapper); the image_generation tool (its answer is an image); and tools whose calls your app runs but a check can't read: custom, computer_use_preview, computer, local_shell, shell, apply_patch, and tool_search run by your app.

Handed on unread, as for chat: tools OpenAI runs itself (web search, file search, code interpreter, remote MCP, including an MCP approval request) run at OpenAI before the answer comes back; their items, and their queries, arguments and results, reach your app unread. So do refusals and reasoning. An answer that holds anything else (a call of a tool type above, a generated image, an item or event a check doesn't know) is withheld: NorcasterCannotCheck with about == "answer".

responses.parse and responses.stream are covered too: see The provider's parse and stream helpers. responses.retrieve and the rest raise and point to your own client.

The OpenAI Agents SDK can run on a wrapped async client. Pass use_for_tracing=False: by default the Agents SDK reads the client's API key for its traces, which the wrapper does not give out.

from agents import set_default_openai_client
from openai import AsyncOpenAI

set_default_openai_client(client.wrap_openai(AsyncOpenAI(), check_output=True), use_for_tracing=False)

It calls responses.create, so everything above applies: an agent with a stored prompt is not sent, tools OpenAI runs are handed on unread, and with check_output=True the tools listed above are refused. Its websocket model does not go through the wrapper. Tried with openai-agents 0.24.0.

The provider's parse and stream helpers

From 0.1.6 the wrapped client also has the helpers many apps call instead of create:

  • OpenAI: chat.completions.parse and chat.completions.stream, responses.parse and responses.stream.
  • Anthropic: messages.parse and messages.stream.
from openai import OpenAI
from pydantic import BaseModel
from norcaster import norcaster_check, norcaster_output_check


class Contact(BaseModel):
    name: str
    email: str


openai_client = client.wrap_openai(OpenAI(), check_output=True)

completion = openai_client.chat.completions.parse(
    model="gpt-4o-mini", messages=messages, response_format=Contact
)
contact = completion.choices[0].message.parsed  # built from the checked answer

with openai_client.chat.completions.stream(model="gpt-4o-mini", messages=messages) as stream:
    for event in stream:
        ...
print(norcaster_check(stream).receipt_id, norcaster_output_check(stream).receipt_id)

A helper's request goes through the wrapper's checked create, so what is above applies to it as to create: your app asks Norcaster before the provider is called, on hide Norcaster's version is sent, and a request create refuses is refused by the helper too. What the helper hands back (the parsed object, the stream's events, the final message) is built by the openai or anthropic package's own code. With check_output=True the answer is checked before anything parses it, so parsed, output_parsed, parsed_output and each tool call's parsed_arguments come from the checked answer, or from Norcaster's hidden version on hide. A streamed answer is held and checked once, as for create(stream=True): the stream's first event comes after Norcaster has decided.

  • A stream helper asks Norcaster when the request is made, as you enter with (or async with), not when you call stream(...). A request that would not be sent is refused at stream(...).
  • On hide, if Norcaster's hidden version no longer fits the format you asked for (a field whose pattern a hidden email no longer matches, say), parse withholds the answer: NorcasterCannotCheck with about == "answer". A stream raises the provider's own parse error when it gets there.
  • An allowed answer that doesn't parse raises the provider's own error, as without the wrapper.
  • norcaster_check(...) and norcaster_output_check(...) work on what parse returns and on the stream you get from with.
  • parse doesn't take stream. responses.stream for a response made earlier (response_id, starting_after) is refused: OpenAI sends that answer without a request to check.
  • The helpers use the parse and stream parts of the package your client comes from. With a version that doesn't have them, the helper is refused before anything is sent (NorcasterCannotCheck), and create still works. Tried with openai 2.26.0 and anthropic 1.11.0.

Still not covered, and raising so you make the call on your own client: responses.retrieve, token counting (messages.count_tokens, responses.input_tokens), embeddings, beta (OpenAI's old beta.chat.completions.parse is chat.completions.parse now), with_raw_response and with_streaming_response.

Amazon Bedrock (Converse)

From 0.1.7, client.wrap_bedrock(...) takes your own boto3 Bedrock Runtime client and asks Norcaster before each converse and converse_stream, with everything above: allow, hide and block, when_unreachable, check_output, held streams, and images and documents described, not read. An aioboto3 or aiobotocore client works the same way with await.

import boto3
from norcaster import NorcasterBlocked, norcaster_check

bedrock = client.wrap_bedrock(boto3.client("bedrock-runtime"), check_output=True)

try:
    answer = bedrock.converse(
        modelId="eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
        system=[{"text": "Be brief."}],
        messages=[{"role": "user", "content": [{"text": "Summarise the ticket."}]}],
    )
except NorcasterBlocked as blocked:
    print(blocked.about, blocked.receipt_id)
else:
    print(answer["output"]["message"]["content"], norcaster_check(answer).receipt_id)

What the check reads. Norcaster has no request shape of Bedrock's own, so the wrapper reads a Converse request as the same request in the Anthropic Messages shape, and the record and its hash are of that reading:

In the Converse request What the check reads
system: text, guardContent text a leading system message
text, and guardContent text in a message a text block
image, guardContent image, document (bytes) an image or document: its description, never its bytes
image or document from an s3Location a reference: its s3:// URI is read as text
document from text or content, its name and context the document's text, name and context
toolUse (history) a tool_use block: its name, and its input
toolResult a tool_result block: text, a json result as its JSON text, images, documents, search results
searchResult, citationsContent (an earlier answer sent back) their text
an assistant message with reasoningContent left out, and sent exactly as it was: the provider signs it
cachePoint nothing: it holds no content
toolConfig (the tool definitions), inferenceConfig, guardrailConfig, outputConfig, requestMetadata and the other settings not read, as for the other wrappers; sent as they are

On hide the wrapper sends your request with Norcaster's hidden text in the places it came from. A hidden version that would change anything else (an image, a document's bytes, name or S3 location, a tool's name or id) is not sent: NorcasterCannotCheck.

Not sent, because what they carry would reach the model without a check (NorcasterCannotCheck, before anything is sent):

  • a prompt stored in Bedrock Prompt management (a prompt ARN as modelId, or promptVariables);
  • text in additionalModelRequestFields: Bedrock passes that field to the model. Settings are sent: numbers, true or false, and text under type, anthropic_beta, reasoning_effort, effort or maxReasoningEffort (Claude's thinking and betas, Nova's reasoningConfig);
  • video and audio blocks (the check takes images and documents only), and legacy Office files (doc, xls: their type can't be told from their bytes, so document rules would always block them);
  • a list nested directly in a list, in a tool's input: a check doesn't read it;
  • a block or a parameter this version doesn't know (toolAddition, toolRemoval): a newer SDK may check it.

The answer, with check_output=True: the text of its text blocks, run together, and the tool calls it asks for (each toolUse block your app runs: its name and its input as JSON). On hide your app gets the hidden text in the first text block, the others emptied, and each tool call's input hidden (still an object of the same shape); the Bedrock Guardrails trace (trace.guardrail), which can quote the answer, is removed. Tools Bedrock runs itself (server_tool_use), their results and reasoning are handed on unread. An answer with citations, an image, video, audio or a document is withheld; so a document with citations turned on is refused before anything is sent.

converse_stream with check_output=True reads Bedrock's whole stream, asks once, and then gives your app the result with stream replaced by Bedrock's own events, held (CheckedStream, or AsyncCheckedStream). Your app gets the first event after Bedrock has finished and Norcaster has decided. Without check_output the stream is Bedrock's own.

  • The result is the dict Bedrock returned (a BedrockResult, a dict subclass), so norcaster_check(result) and norcaster_output_check(result) work on it.
  • bedrock.exceptions is your client's, for except bedrock.exceptions.ThrottlingException.
  • Everything else raises and points to your own client: invoke_model and invoke_model_with_response_stream (their body differs for every model family; for Claude, wrap an AnthropicBedrock client with wrap_anthropic), apply_guardrail, count_tokens, and the rest.

examples/check-mode/bedrock_converse.py runs each case against your own Norcaster app, with Bedrock answered locally.

Google Gemini

From 0.1.7, client.wrap_gemini(...) takes your own google-genai client, for the Gemini API or for Vertex AI, and asks Norcaster before each models.generate_content and models.generate_content_stream, and the same on aio.models, with everything above: allow, hide and block, when_unreachable, check_output, held streams, and images, documents and audio described, not read.

from google import genai
from norcaster import NorcasterBlocked, norcaster_check

gemini = client.wrap_gemini(genai.Client(), check_output=True)

try:
    answer = gemini.models.generate_content(
        model="gemini-3-flash", contents="Summarise the ticket.", config={"system_instruction": "Be brief."},
    )
except NorcasterBlocked as blocked:
    print(blocked.about, blocked.receipt_id)
else:
    print(answer.text, norcaster_check(answer).receipt_id)

What the check reads. Norcaster has no request shape of Gemini's own, so the wrapper reads a Gemini request as the same request in the OpenAI Responses shape (the one that holds images and files inline or by URL, inline audio, and function results with media), and the record and its hash are of that reading. contents is normalised as the google-genai client normalises it (strings, parts, PIL images, dicts), and the wrapper sends that normalised list:

In the Gemini request What the check reads
config.system_instruction a leading system message
a content's text a text part
inline_data image, document (PDF, text, Office, CSV) or audio (WAV, MP3, AAC, FLAC, Ogg, WebM, M4A) its description, never its bytes
file_data (a gs://, https:// or Files API URI) a reference: the URI is read as text
function_call (history) a function_call item: its name, and its args as JSON text
function_response a function_call_output item: its response as JSON text, and its images and files
executable_code / code_execution_result (code Gemini ran, in history) their text
a model turn with a thought, a thought signature, or a call to a tool Google runs left out, and sent exactly as it was: Gemini needs it back unchanged
the tool definitions, Google's own tools (search, URL context, code execution, retrieval, file search, maps, Google-run MCP servers), and settings (safety_settings, thinking_config, response_schema, labels and the rest) not read, as for the other wrappers; sent as they are

On hide the wrapper sends your request with Norcaster's hidden text in the places it came from. A hidden version that would change anything else (an image, a file's URI, a function's name or id) is not sent: NorcasterCannotCheck.

Not sent, because what they carry would reach the model without a check (NorcasterCannotCheck, before anything is sent):

  • Gemini's stored content (cached_content);
  • an extra body (http_options.extra_body), on the call or on the client: the client merges it into the request. A client made with one can't be wrapped;
  • automatic function calling: with a Python function or an MCP session among tools, the google-genai client calls it and sends its result to the model inside one call, before any check. Turn it off with automatic_function_calling={"disable": True}, run the function yourself, and send its result in the next checked call;
  • video (inline, by URI, or YouTube), audio by URI, and AIFF audio; legacy Office files;
  • a part holding text in part_metadata, a thought outside a model turn, a function call in pieces;
  • a config field this version doesn't know: a newer SDK may check it.

Automatic continuation (on by default) re-sends the same checked request with Gemini's token; the answer is checked whole.

The answer, with check_output=True: the text of its parts (not thoughts) and the function calls it asks for (each name, and its args as JSON). On hide your app gets the hidden text in the first text part, the others emptied, and each function call's args hidden (still an object of the same shape); the token log-probabilities, the citations and the grounding supports, which point into or quote the original answer, go with it; and parsed is built again from the hidden text by the google-genai client's own parser (a hidden answer that no longer fits your schema is withheld). Code Gemini ran, Google-run tools and thoughts are handed on unread; an image, audio or a file in the answer is withheld. Refused before anything is sent with check_output=True: more than one candidate, an answer that isn't text (response_modalities, speech_config), the raw HTTP response (should_return_http_response), a continuation_token of your own, output persisted to external storage (generation_output_config), and computer_use.

generate_content_stream with check_output=True reads Gemini's whole stream, asks once, and then gives your app Gemini's own chunks, held (CheckedStream, or AsyncCheckedStream on aio.models). Without check_output the stream is handed on as it comes.

Chats. gemini.chats.create(...) (and gemini.aio.chats.create(...)) makes google-genai's own chat around the checked calls, so send_message, send_message_stream and get_history work as they do on your client:

chat = gemini.chats.create(model="gemini-3-flash", config={"system_instruction": "Be brief."})
first = chat.send_message("Why does this connection fail? postgresql://app:s3cretpw@db/prod")
second = chat.send_message("And how do I fix it?")
  • Each send is one checked generate_content of the chat's history and the new message, so every turn checks the whole conversation again: text hidden on one turn is hidden again on the next, before Gemini sees it, and each turn's record shows it.

  • The history keeps what you sent and what you got: an answer Norcaster hid stays hidden in it. A turn that was blocked (NorcasterBlocked) is not recorded, and the chat goes on.

  • The chat runs automatic function calling with Python functions itself, one checked call per step, with the step's function results in it. With check_output=True your function gets the arguments the answer check left, and a blocked answer stops the loop before the function runs.

  • A chat's stream is a generator: the request is checked, and a block raises, when you start reading it. google-genai records each streamed chunk in the history as a turn of its own.

  • norcaster_check(...) and norcaster_output_check(...) work on what the calls return, and on each chunk of a stream (a chat hands on the chunks, not the stream).

  • Everything else raises and points to your own client: the Interactions API, caches, files, live, batches, embeddings, token counting, and image and video generation.

examples/check-mode/gemini.py runs each case against your own Norcaster app, with Gemini answered locally.

When Norcaster can't be reached

By default the request is blocked: NorcasterUnreachable is raised and the provider is not called. "Can't be reached" means no connection, no answer within timeout (10 seconds unless you set it), or an error on Norcaster's side.

You can set an app to let requests through instead:

openai_client = client.wrap_openai(
    OpenAI(),
    when_unreachable="let_through",
    on_unchecked=lambda unchecked: audit_log.warning("sent without a check: %s", unchecked.id),
)

Every request that is let through is recorded, each time:

  1. It is written to the norcaster.check log as a warning.
  2. It is passed to on_unchecked.
  3. It is sent to Norcaster after the next check that succeeds, and shows in your records as "Let through without a check". Call client.report_unchecked() before your app stops, to send what is still waiting.

The record holds a SHA-256 of the request, when it happened and why. It never holds the request itself. No rule ran on a request that was let through, and it is not counted as a check.

Know these limits before you turn it on:

  • A request that is let through goes to the provider as your app wrote it. Nothing is hidden.
  • Requests waiting to be sent to Norcaster are kept in memory. If the app stops before Norcaster answers again, your own log line is the only record.
  • At most 10,000 wait at a time. Past that, requests are blocked.
  • A refusal from Norcaster always blocks, whatever the setting: a wrong or revoked key, a missing scope, a stopped app, the rate limit, or more than 1,000,000 characters. These raise NorcasterCheckRefused.

examples/check-mode/sample_app.py runs all of this against a stand-in provider; add --answers for the answer checks.

Metadata

Release files for norcaster 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for norcaster 0.1.7
File Size Uploaded Provenance Actions
norcaster-0.1.7.tar.gz 95.7 kB Without provenance Details for norcaster-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for norcaster 0.1.7
File Interpreter ABI Platform Actions
norcaster-0.1.7-py3-none-any.whl Python 3 none any Details for norcaster-0.1.7-py3-none-any.whl

Total release size: 185.6 kB

Release files / norcaster-0.1.7.tar.gz

Download URL norcaster-0.1.7.tar.gz
Size 95.7 kB
Tags Source
SHA-256 checksum
How to use checksums
631558b1959c9b52613a8e8f431529e5425c64d67058061b6ff0c4dc41b6a330
BLAKE2b-256 checksum
How to use checksums
209bc7e73d1e7b78096c2d1ea31218dba1d373a9d5a8b43f47fa93d1ea039fb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / norcaster-0.1.7-py3-none-any.whl

Download URL norcaster-0.1.7-py3-none-any.whl
Size 89.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
048a5ea8400db238ac7055a19dfad57be0a8970db976c8ed327767fa68fda747
BLAKE2b-256 checksum
How to use checksums
d3a8fc2e6f92d5b11d7a6b2a0c194e34a1cef2c49324d89e1b38857981efd5dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Security for norcaster 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page