switch_trust.wrap(), while Google ADK uses a dedicated plugin.
OpenAI
Wrap anopenai.OpenAI() client to route completions through the guardrails proxy.
Anthropic
Wrap ananthropic.Anthropic() client the same way.
Google GenAI
Google GenAI clients don’t exposeapi_key as an attribute, so llm_api_key can’t be auto-extracted. To forward a key, pass it explicitly:
The SDK automatically normalizes the gateway URL with a trailing slash for Google GenAI — do not add one yourself.
LangChain
switch_trust.wrap() auto-detects LangChain chat models, extracts the underlying SDK client, and applies guardrails routing. Supported models:
ChatOpenAI(fromlangchain-openai)ChatAnthropic(fromlangchain-anthropic)ChatGoogleGenerativeAI(fromlangchain-google-genai)
- ChatAnthropic
- ChatGoogleGenerativeAI
LangChainGuardrailsMiddleware instead:
Google ADK
ADK agents lazily create their GenAI client at runtime, soswitch_trust.wrap() cannot be used. Use ADKGuardrailsPlugin to configure guardrails routing at the agent level:
- Routing —
content_configdirects LLM traffic through the guardrails proxy - Identity —
before_model_callbackinjects agent name, agent ID, and session ID headers on each call - Error handling —
on_model_errorconverts guardrails blocks into anLlmResponsethe agent can handle gracefully
Version compatibility
Pin your provider SDK to the tested ranges to avoid breakage from private API changes:
The SDK logs a warning if your installed provider version is outside these ranges.
Known limitations
- Private attribute mutation —
switch_trust.wrap()modifies internal attributes of LLM SDK clients (_base_url,_custom_headers,_api_client._http_options) to redirect traffic. These are not part of the providers’ public APIs and may change without notice. - Async clients —
AsyncOpenAIandAsyncAnthropicare not supported. Use sync clients only. - Google GenAI
api_key— Google GenAI clients don’t exposeapi_keyas an attribute, soforward_llm_key=Truecan’t take the key from the client. To forward a key, passllm_api_keyor setSWITCH_TRUST_LLM_API_KEY. Otherwise, the request uses the client’s own key. - Multiple provider keys in environment — If multiple provider API keys are set (
OPENAI_API_KEY,ANTHROPIC_API_KEY,GOOGLE_API_KEY), auto-detection fails. Passproviderexplicitly toswitch_trust.init().
Next steps
Usage
Advanced patterns, error handling, and best practices
Configuration
Environment variables, credentials, and gateway setup

