Blocking LangChain fallback chains from failing over to a non-BAA model
A LangChain fallback retries a failed call against another model, and unless every reachable model is covered by a BAA, a failover can send PHI to a provider that is not. Restricting fallback lists, narrowing which exceptions trigger failover and scoping credentials all reduce the risk, but they are configuration and can drift. Enforcing a model allowlist at runtime, in the execution path, blocks the call itself and produces per-request evidence of what happened.
Evidence to retain for each request
- Request identifier and timestamp
- Model and provider requested by the application
- Model and provider that actually executed the call
- Each failover attempt, including the target and the error that triggered it
- Policy decision for each attempt (allow, redact or block) and the policy version applied
- Identity of the calling application or service
- Retention period and access controls applied to the evidence record
How LangChain fallbacks decide where a prompt goes next
LangChain's with_fallbacks pattern wraps a primary runnable with an ordered list of alternates. When the primary call raises an error that the wrapper is configured to handle, the same input is passed to the next runnable in the list, and so on until one succeeds or the list is exhausted. Router-style and runnable-based patterns reach the same outcome with custom logic: application code decides which model receives the input after a failure or based on a condition.
Two properties matter for compliance. First, the input is the full prompt, including any PHI that was in the original request. Second, the retry target is chosen by application code and configuration, not by any check on whether the receiving provider has a BAA covering the specific model, endpoint and deployment in use. The chain optimizes for availability. It has no notion of contractual coverage.
This is why NIST AI 600-1, voluntary guidance rather than a HIPAA requirement, calls for policies and procedures to test and manage risks related to rollover and fallback technologies, and for documenting fallbacks in the generative AI value chain. A fallback target is a third-party dependency and belongs in that inventory.
The paths through which PHI reaches a non-BAA model
A fallback list that was approved at design time can still become a route to an uncovered model. The common paths are worth enumerating, because each maps to a different control.
Fallback list drift is the simplest. Someone adds a model to improve availability or test a new provider, and the change passes review because it looks like a resilience improvement. Broad exception handling is subtler. If the chain handles a wide class of exceptions, then authentication errors, validation failures and provider-side rejections can all trigger failover, not just transient outages. A prompt that one provider declined may then be sent to another.
Configuration-driven model names add a third path. When model identifiers or endpoints come from environment variables or shared settings, a deployment change can point a fallback at a model or endpoint the BAA does not cover, with no change to the chain code. Router logic and fallbacks defined inside shared helpers or nested chains add a fourth: the reachable set of models is not visible at the call site. Finally, agents and tools that make their own model calls can introduce targets that no one reviewed alongside the primary chain.
In every case the same gap appears afterward: teams struggle to show which model actually processed a given request.
Application-level mitigations and their limits
These controls are worth implementing regardless of what else you deploy. They lower the probability of an unintended failover. They do not make it impossible.
- Restrict fallback lists to an approved inventory: Define fallback targets in one module generated from a reviewed list of BAA-covered models. Confirm coverage for the specific model, endpoint and deployment type you call. Limit: the list is still code, and drift or a parallel chain bypasses it.
- Narrow the exceptions that trigger failover: Set exceptions_to_handle to the transient availability errors you intend to fail over on, not a broad base class. Limit: a later change can widen it, and the change looks harmless in review.
- Fail closed or use a non-model path: When no approved target is available, return an error or route to a manual process. NIST AI 600-1 acknowledges that fallback may include manual processing. Limit: this trades availability for compliance, so it needs an explicit decision.
- Scope credentials by provider: Give the runtime only the keys for approved providers, so a call to any other provider fails for lack of credentials. Limit: it does not distinguish between covered and uncovered models within one provider.
- Apply egress controls: Permit outbound traffic only to approved provider endpoints. Limit: it works at the network level and cannot see which model a request names or whether it contains PHI.
- Test failover by forcing errors: Inject failures in CI and assert that the chain never reaches a target outside the inventory. Limit: tests cover the paths you thought of, at the time you ran them.
Why runtime enforcement is a stronger control than configuration
Every mitigation above acts before the request, through code, configuration or network rules. Each depends on someone keeping the configuration correct and on reviewers noticing when it changes. Static allowlists and code review answer the question of what the system was meant to do. They do not establish what it did on a given request.
Enforcing the allowlist at runtime, in the execution path, changes the control point. The policy is evaluated on each call, using the model the request actually names at that moment. If a fallback attempts an unapproved target, the call is blocked regardless of how the chain was configured, which exception triggered the attempt or which helper module defined the list. Policy can also distinguish between outcomes: allow the call, redact sensitive content before it proceeds, or block it.
This does not replace the in-code controls. A restricted fallback list keeps the chain behaving predictably, and a runtime check catches the case where it does not. The two layers fail independently, which is the point. The tradeoff is an additional component in the request path, so evaluate its latency, availability and failure behavior as you would for any dependency that every model call traverses.
Where Trussed fits as one enforcement approach
Trussed enforces policy in the execution path across models and agents, including blocking requests to models that are not approved. For a LangChain deployment, that means a failover attempt to a non-approved model is stopped at runtime, enforced at runtime, not reviewed after the fact. Policies can allow, redact or block, and apply to individual interactions and tool calls.
Enforcement generates continuous, audit-ready evidence that is mapped to HIPAA, so the record of which model handled a request and which attempts were blocked comes from the control itself. Trussed can be deployed self-managed in the customer cloud, with configurable retention and data residency. It runs in production for regulated enterprises, with 100+ models under one policy plane.
The approach is useful only if the underlying inventory is right. Decide which models are covered by a BAA for your specific endpoints first, then enforce that list. Whatever tooling you choose, the evaluation questions are the same: is the allowlist enforced in the path, does it handle fallbacks and agent tool calls, and can it show you the executed model for any request.
Where a failover decision meets policy
Primary call fails
A handled error triggers the fallback logic in the chain.
Fallback target selected
The next model in the list or router is chosen by application code.
Runtime policy check
The target is compared with the approved model allowlist before any prompt leaves.
Allow, redact or block
Approved targets proceed. Non-approved targets are stopped.
Evidence recorded
The requested model, executed model and decision are retained per request.
Check your fallback paths against a runtime control
Walk through your chains, fallback targets and evidence fields with our team, and see how enforcement in the execution path blocks non-approved models.
Request a DemoHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.