wrap() for standard LLM clients, and a dedicated plugin for the Google ADK agent framework.
Basic wrapping
Callwrap() on your existing LLM client. The SDK auto-detects the provider, rewrites the client’s base URL to route through the guardrails proxy, and injects authentication headers. The client is mutated in place, and the same instance is returned.
wrap() options
Explicit initialization
For more control, useinit() to initialize the SDK separately from wrapping. This is useful when registering plugins, or when you want to configure guardrails once and wrap several clients.
init() accepts the same guardrails options as wrap(), plus:
Pass
provider to disambiguate when several provider API keys are present in the environment (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY), which otherwise makes auto-detection fail.
Shutdown
Callshutdown() to clean up resources:
Inspect guardrails status
Callstatus() to confirm traffic is actually being routed through the gateway rather than trusting configuration alone:
active is true only when traffic is routed through the gateway.
Google ADK
ADK agents lazily create their GenAI client at runtime and usegenerateContentConfig for per-request routing, so wrap() cannot be used. Use ADKGuardrailsPlugin instead:
Agent:
contentConfig— Configures HTTP options so LLM traffic routes through the guardrails proxy.beforeModelCallback— Extracts the ADK session ID and attaches it as anX-Agent-Session-Idheader on each guardrails request.ADKGuardrailsPlugin.onModelError— A static callback that converts guardrails blocks (identified by theGUARDRAIL_BLOCKEDerror code) into anLlmResponseso the agent can handle them gracefully.
LangChain
wrap() auto-detects LangChain chat models, finds the underlying SDK client, and applies guardrails routing. Create your chat model as usual, then wrap it:
ChatOpenAI, ChatAnthropic, and ChatGoogleGenerativeAI.
Error handling
wrap() and init() throw FlintAIGuardrailsError when a valid client is passed but guardrails can’t be applied and requireGuardrails is true (the default) — for example, when gatewayUrl or apiKey is missing and no environment variables are set.
Passing an unrecognized client type throws a TypeError rather than FlintAIGuardrailsError.
Global state
Eachwrap() call updates the global SDK client’s guardrails config. If you wrap several clients with different options, each client keeps its own headers and base URL, but only the last wrap() call’s config is stored globally. For most applications — a single provider with shared credentials — this is transparent.
Plugins
Plugins handle events from the SDK lifecycle. ExtendFlintAIPlugin and override the methods you need, then register the plugin:
Best practices
- Use environment variables for credentials instead of hardcoding them. See Configuration.
- Pin your provider SDK versions to the tested ranges to avoid breakage from private API changes. See Integrations for version compatibility.
- Wrap once per client during startup. The SDK mutates the client in place.
- Reserve
dangerouslyDisableGuardrailsfor development. In production, fail-closed behavior ensures traffic is never sent without guardrails.
Next steps
Integrations
Provider-specific setup and version compatibility
Configuration
Environment variables, credentials, and gateway setup