Impraint

Quickstart

Track your first agent function with Impraint Guard.

This takes about five minutes. You'll create a Guard, patch Gemini, wrap one function with @guard.track, and see the trace in your dashboard.

Install the SDK

pip install "impraint-guard[beta]"
export IMPRAINT_API_KEY="your-api-key"
export GEMINI_API_KEY="your-gemini-key"

During beta, your Impraint contact gives you the Guard API key. See Installation.

Create a Guard and patch Gemini

Create one Guard per agent. The agent_id is how the agent appears in your dashboard. Call patch_gemini(guard) once at startup, before any Gemini call.

import os
from google import genai
from impraint_guard import Guard
from impraint_guard.integrations.gemini import patch_gemini

guard = Guard(
    api_key=os.environ["IMPRAINT_API_KEY"],
    agent_id="support-agent",
)
patch_gemini(guard)

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

Track a function

Decorate the function that represents one run of your agent. Each call becomes one trace, and the Gemini call inside it is recorded as a step with tokens and cost.

@guard.track
def answer_question(question: str) -> str:
    resp = client.models.generate_content(
        model="gemini-2.5-flash",
        contents=question,
    )
    return resp.text

Calls are only recorded inside @guard.track

Outside a tracked function, the Gemini patch does nothing. Make sure the model call happens inside a function decorated with @guard.track.

To label what kind of action a function is, pass an ActionType:

from impraint_guard import ActionType

@guard.track(action_type=ActionType.TOOL_CALL)
def lookup_order(order_id: str) -> dict:
    ...

Run it

print(answer_question("What is your refund policy?"))
guard.shutdown()  # flushes queued traces before the process exits

shutdown() is worth calling in short scripts so the last traces are sent before the process ends.

Open the dashboard

Open guard.impraint.com, go to the Traces page and find the trace under your agent.

What if Guard is down?

Nothing breaks. Guard is fail-open by default: if it can't reach the server, it logs a warning and your function still returns normally. The one exception is an invalid API key, which raises an error when the Guard is created.

Next steps

On this page