Skip to main content
The Flint AI Python SDK provides two integration paths: flintai.wrap() for standard LLM clients, and framework-specific plugins for agent frameworks like Google ADK and LangChain.

Basic wrapping

Call flintai.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.
Set FLINTAI_GATEWAY_URL and FLINTAI_API_KEY as environment variables, then call flintai.wrap(client) without parameters. See Configuration for details.

wrap() parameters

Explicit initialization

For more control, use flintai.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

Call flintai.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, so flintai.wrap() cannot be used. Use ADKGuardrailsPlugin instead:
Set FLINTAI_GATEWAY_URL, FLINTAI_API_KEY, and FLINTAI_LLM_API_KEY as environment variables (or in a .env file), then create the plugin with no arguments: ADKGuardrailsPlugin().
The plugin provides three components to pass to the ADK Agent:
  • content_config — Configures HTTP options to route requests through the guardrails proxy
  • before_model_callback — Injects agent identity (X-Agent-Id, X-Agent-Name from the callback context or AGENT_NAME env var) and session ID (X-Agent-Session-Id) headers on each LLM call
  • on_model_error — Converts guardrails blocks (detected via the GUARDRAIL_BLOCKED error code) into an LlmResponse so 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, use LangChainGuardrailsMiddleware to intercept model calls and inject guardrails routing:
Set FLINTAI_GATEWAY_URL and FLINTAI_API_KEY as environment variables, then create the middleware with no arguments: LangChainGuardrailsMiddleware().
The middleware automatically:
  • 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_id from the LangChain runtime config and attaches it as X-Agent-Session-Id

Error handling

The SDK raises FlintAIGuardrailsError when guardrails can’t be applied and require_guardrails is True (the default). Common scenarios:
  • Missing gateway_url or api_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 using ADKGuardrailsPlugin

Thread safety

  • flintai.init(), flintai.wrap(), and flintai.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=False only 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