flintai.wrap() for standard LLM clients, and framework-specific plugins for agent frameworks like Google ADK and LangChain.
Basic wrapping
Callflintai.wrap() 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 same client instance is returned — mutated in place.
wrap() parameters
Explicit initialization
For more control, useflintai.init() to initialize the SDK separately from wrapping. This is useful when registering plugins or when you want to configure guardrails once and wrap multiple clients.
init() accepts the same guardrails parameters as wrap(), plus:
Shutdown
Callflintai.shutdown() to clean up resources and restore wrapped clients to their original configuration. The SDK registers an atexit handler automatically, so explicit shutdown is optional in most cases.
Google ADK
ADK agents lazily create their GenAI client at runtime, soflintai.wrap() cannot be used. Use ADKGuardrailsPlugin instead:
Agent:
content_config— Configures HTTP options to route requests through the guardrails proxybefore_model_callback— Injects agent identity (X-Agent-Id,X-Agent-Namefrom the callback context orAGENT_NAMEenv var) and session ID (X-Agent-Session-Id) headers on each LLM callon_model_error— Converts guardrails blocks (detected via theGUARDRAIL_BLOCKEDerror code) into anLlmResponseso the agent can handle them gracefully instead of crashing
The
before_model_callback fails closed by default. If guardrails routing was never applied (the request has no http_options), it raises FlintAIGuardrailsError. Pass require_guardrails=False to the plugin for best-effort behavior.LangChain middleware
For LangChain agents, useLangChainGuardrailsMiddleware to intercept model calls and inject guardrails routing:
- Detects the underlying SDK client (OpenAI, Anthropic, or Google GenAI) from the LangChain chat model
- Applies guardrails routing on the first model call
- Extracts
thread_idfrom the LangChain runtime config and attaches it asX-Agent-Session-Id
Error handling
The SDK raisesFlintAIGuardrailsError when guardrails can’t be applied and require_guardrails is True (the default). Common scenarios:
- Missing
gateway_urlorapi_key(and no environment variables set) - Unrecognized client type passed to
wrap() - Async client passed to
wrap()(not supported) - ADK agent passed to
wrap()instead of usingADKGuardrailsPlugin
Thread safety
flintai.init(),flintai.wrap(), andflintai.shutdown()are not thread-safe. Call them from the main thread during application startup.- Once initialized, wrapped clients are thread-safe — the underlying SDK clients handle their own concurrency.
- Double-wrapping is safe — the SDK detects already-wrapped clients and skips them with a warning.
Async clients
Async clients (AsyncOpenAI, AsyncAnthropic) are not supported. Use sync clients only. Passing an async client to wrap() raises a TypeError.
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, so wrapping the same client multiple times is a no-op (with a warning).
- Use
require_guardrails=Falseonly in 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