Replacing an AI provider: capability compatibility matters more than the model name

Admit a fallback route only while preserving required capabilities and the response schema, classify the reason for switching, and independently validate returned data.

Different instruments represent capabilities that must be matched to a requirement.
Different instruments represent capabilities that must be matched to a requirement.

An application has two routes to language models. The primary route is temporarily unavailable, and the backup responds. It might seem sufficient to change the address and repeat the request. But the task expects a structured object and a tool request, while the backup can return only a structured answer. The resulting text may look convincing even though the required operation has already changed.

Replacing a provider requires a more precise unit of comparison than a model name. I need a task contract: required capabilities, the result format, an allowed reason for switching, and a way to validate the response. If the backup route cannot satisfy that contract, rejection before dispatch is a correct outcome. An available model is not automatically a suitable model.

Describe the required result first

The independent teaching model has two invented routes, A and B. They do not identify particular suppliers or describe the capabilities of live models. A declares support for structured JSON and tool requests. B declares support for structured JSON only. These values are a fixture that can be checked locally without a network or keys.

The task returns an object under one schema, answer.v1. It has two required fields: answer, a nonempty string of at most 120 characters, and tool_requests, an array containing at most one request. An allowed request has the name lookup_term and an arguments object containing term. Unrecognized fields are not an arbitrary extension of the agreement.

Task variant Required capabilities Additional result rule
Structured answer structured_json tool_requests is empty
Answer with a tool request structured_json, tool_requests Exactly one allowed request

Both variants use the same schema and its fingerprint. A separate domain rule specifies the number of requests allowed for a particular task. Passing JSON Schema validation therefore does not finish the check: an object with an empty array can be structurally valid while failing a task that requires a tool.

A tool request is only data here. The example does not run lookup_term, read external sources, or execute commands from the response. Permission for a model to propose an action differs from permission for the application to perform it. A real tool would need its own permissions, argument restrictions, and verification of the effect.

A capability declaration is not proof

The capability matrix helps reject unsuitable routes in advance. If a task requires tool_requests, B fails admission regardless of the quality of its prose. A missing value does not mean true either: an incomplete matrix must stop selection.

The teaching vocabulary allows exactly two known capabilities. An unknown name, a missing field, or a value of the wrong type is a configuration error. This deliberately closes the format of a small exercise. A general product can have an extensible capability registry, but each consumer must still understand what it requires. Adding a declaration does not automatically establish support.

Three claims need to remain separate. A route declared a capability. A policy admitted it for a particular request. The returned response passed local validation. The first supports selection, the second explains a decision, and the third concerns actual result data. None of them alone establishes that the answer's content is correct.

Fallback needs a named reason

The model permits one automatic transition: A is known to be unavailable before dispatch, and policy explicitly allows the backup route. That state is named known_unavailable_before_dispatch. It differs from an arbitrary exception, an error message, or an unknown outcome after a request has started.

Following that rejection, the system checks the task requirements again, this time against B. A structured task can pass; a task requiring tools cannot. In the latter case, B's invocation counter must remain zero. Removing the tool requirement, obtaining ordinary text, and calling it successful fallback would silently create a different task.

Condition Observed fake-model decision What stays unchanged
A is available and supports the contract Dispatch to A Schema and requirements
A is known unavailable before dispatch; only JSON is required Explicitly select B The same schema and result rules
A is unavailable in the same way; a tool is required Reject before dispatch to B The tool requirement
Unknown capabilities or invalid configuration Reject before calls No guessing about support

These transitions were reproduced in a local Python run with fake adapters: the permitted structured task moved to B while preserving its contract, and the task requiring a tool stopped before a backup invocation. Authentication, policy, and format errors did not trigger fallback; a timeout after dispatch retained an unknown outcome. The run called no live model or tool.

The table describes the teaching model, not a provider availability ranking. Another product can agree on other reasons for switching. Those reasons must appear as explicit policy with examples of allowed behavior, rather than as a side effect of a generic catch.

Not every error permits a route change

An authentication error can mean incorrect credentials or missing permission. A policy refusal can concern the task itself. Automatically bypassing it through another route is a separate decision that this example does not authorize. Both states end the attempt without a backup invocation.

Malformed JSON is not a signal that “A is unavailable before dispatch” either. A response has arrived, but it violates the contract. The recorded outcome must be validation failure. Otherwise, the history would show a successful backup result while hiding the primary route's failure to meet expectations.

A timeout after dispatch has another complication: the external system may have started or completed the work. The timeout alone does not establish that no result exists. It does not trigger fallback in this model. This is a route-selection boundary, rather than a complete retry, idempotency, or remote reconciliation protocol.

The adapter response remains untrusted

After admission, the route returns an envelope containing its identity, the request identity, the schema fingerprint, and the response body. Those bindings must be checked before parsing the body. Valid JSON from another request is not the current request's result, even if it contains every required field.

The request ID must also encode as strict UTF-8. A lone surrogate is rejected as request_invalid; the optional safe fingerprint for a rejected request may be None. Computing that fingerprint in the exception handler must not cause another failure. There is no lossy encoding fallback.

The next boundary is size: at most 4,096 bytes. Valid UTF-8, strict JSON parsing, local schema validation, and the tool rule follow. This sequence prevents oversized or invalid data from acquiring trust merely because the adapter returned it in a familiar object.

Python's json documentation describes decoding options and cautions about large untrusted inputs. The standard decoder has behavior that this contract must narrow: duplicate keys must not silently replace each other, and NaN and infinities are not accepted as ordinary values. Invalid encoding is rejected separately. A successful json.loads call without the required options is not yet a successful validation.

The JSON Schema reference distinguishes property definitions, required fields, and additional properties. The schema therefore explicitly sets required and forbids extra fields. Listing a field under properties alone does not make it mandatory. This matters for both the top-level object and nested tool arguments.

If B declares support for the required structure but returns an invalid response, its declaration does not override local rejection. Both routes undergo the same validation. Switching routes cannot replace the schema with a simpler one or allow extra text before the JSON merely to produce a green result.

Counters show where the decision stopped

Fake adapters make selection and invocation separately observable. For the expectation “B does not support the tool,” receiving an error is insufficient: the test must establish that B was never called. Forbidden fallback likewise requires zero backup invocations after an authentication refusal, timeout, or format error.

The local checks cover a normal A response, an allowed transition to B, capability rejection, an incomplete matrix, invalid configuration, and an output-contract violation. Negative cases cover mismatched route, request, or schema bindings in the envelope, duplicate keys, an oversized body, and a field with the wrong type.

In an independent Python 3.12.3 environment with jsonschema 4.26.0, 42 unittest tests passed: the original 41 plus one regression test for a lone surrogate in the request ID. The trace run retained all 38 original cases and their unchanged expected outcomes: 4 validated, 32 rejected, and 2 unknown. That trace run alone recorded 24 fake-adapter invocations. There were no real providers, tools, or retries. Human review remains pending.

This local exercise checks our decisions using invented data. It does not establish that a particular live model supports a declared feature. Even successful fixture execution does not measure accuracy, usefulness, price, or generation latency. Those questions require other inputs and a separate evaluation design.

Replacement must preserve the task

Before connecting a real provider, I would require a verified declaration for the exact route, a fixed contract version, and explicit policy for switching reasons. Next come local validation of every response and separate verification of the supplier's actual capabilities. Passing fake tests does not authorize a production switch.

A useful backup preserves the expected result and explains why it was selected. When that is impossible, visible rejection gives the product a truthful state. This boundary allows a supplier to change without silently losing tools, structure, or the meaning of the original task.

  1. Symfony Core Dependency Injection in practice: changing the notification method without changing the use case
  2. Testing Structured AI responses: validation before changing data
  3. Platform Engineering Timeout after an external request: when the outcome is unknown
  4. Distribution Provider adapters: replacing an external service without rewriting the editorial workflow

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article