TRAIL Search measures how often AI answer engines mention a brand. The number it reports is a rate, and a rate is only as honest as its denominator. An engine that timed out did not say "this brand is absent". It said nothing. Most of the adapter layer exists to keep those two outcomes apart from the first byte of the response to the percentage on the dashboard.

The problem

Answer engines are external services of two kinds. Some are LLM APIs that return text and, when they search the web, a list of sources. Others are search result pages that sometimes show an AI-written answer above the links and sometimes do not. They differ in authentication, response format, rate limits, the way they report sources and the way they fail.

If each engine’s quirks leaked upward, the scoring code would be full of special cases, and every special case would be a place to mistake a failure for a result. The specific mistakes to prevent are these.

  • A timeout recorded as an empty answer, which scores as “not mentioned”.
  • A search page that showed no AI answer recorded as an answer that ignored the brand.
  • An engine with no API key configured counted in every rate as zero.
  • A truncated answer scored as if it were complete.

One interface, one result shape

Every engine implements the same EngineAdapter protocol and returns the same EngineResult. Beyond the answer text and the citations, the result carries four observation axes that say what kind of observation this was.

AxisQuestion it answers
collectionDid the call work? ok, failed with an error code, or not_supported
completionDid the answer finish, or was it cut off by a token limit?
surfaceDid the engine show an AI answer for this query at all?
sourcesWere sources returned, and how were they collected?

The result also records the model the provider actually used, whether a web search was observed, the token usage, and which provider and collection path produced it. The fan-out and the scoring code read these fields and nothing engine-specific.

Classifying a cell

Table of cell outcomes with columns: what happened, recorded as, in the rate, refunded, shown as. Answer returned with brand mentioned: answer plus Mention rows, in the rate, not refunded. Answer returned with brand absent: answer with no Mention, in the rate, not refunded, shown as a real zero percent. The engine showed no AI answer for this query: surface inactive, not in the rate, not refunded, excluded and counted apart. The call raised an HTTP error, timeout or network error: status error, collection failed, with an error code, not in the rate, refunded. No API key configured for the engine: collection not_supported, not in the rate, not refunded, excluded. A note says an engine whose every cell failed is listed as unmeasured and the interface shows a dash, not zero percent.
Figure 1. How each outcome of a cell is recorded, whether it enters the rate, and whether the customer is refunded for it. Only the first two rows are answers.

The rule that turns these records into a rate is one predicate. Comments are translated from the original.

def counts_as_answer(run: Any) -> bool:
    """Does this answer enter the mention and share-of-voice denominator?"""
    if _get(run, "status", "ok") != "ok" or _get(run, "superseded_by"):
        return False
    if not _get(run, "answer_text"):
        return False
    collection = _axis(run, "collection")
    if collection is not None and collection.get("status") != "ok":
        return False
    surface = _axis(run, "surface")
    if surface is not None and surface.get("status") == "inactive":
        return False
    completion = _axis(run, "completion")
    return not (completion is not None and completion.get("finish") in _PARTIAL_FINISH)

A cell enters the denominator only if it is the cell’s final attempt, the call worked, the surface was active, there is a body, and the answer was not truncated, blocked or refused. A refusal that happens to name a brand is not evidence about the brand, so no mentions are extracted from it. Everything else gets an exclusion reason, and the exclusion reasons are counted and stored on the run next to the rate.

Two consequences are visible to the customer. An engine for which no cell produced a valid answer is listed as unmeasured, and the dashboard shows a dash for it instead of 0%. And the cells that failed are the ones that are refunded, so the bill follows the same classification as the metric.

Retries

A call can fail for reasons that pass. The fan-out retries those and only those.

SituationPolicy
HTTP 429 or 503up to two retries, after 1 second and then 3 seconds
The provider sends Retry-Afterhonoured, up to 10 seconds
Waiting for a retryboth concurrency semaphores are released during the sleep
An exception marked no_retrynot retried, whatever its status code
An exception marked transientretried, whatever its status code
Answer cut off by the token limita new attempt with the limit doubled, capped at 8,192 tokens, once

Transport retries stay inside one attempt. A truncation retry is a new attempt and is stored as its own row, with the first attempt pointing to it. The distinction keeps the record honest: the first answer really was returned and really was truncated, and the provider was paid for both.

Timeouts are 10 seconds to connect and 45 seconds to read. A truncation retry asks for a longer answer, so its read timeout grows with the token limit.

Releasing the semaphores during a retry sleep matters under load. A 429 means the provider wants fewer calls. Holding a concurrency slot while sleeping would starve the calls that could proceed.

A fallback path, taken once

One search surface can be collected through two different providers. The adapter tries them in a configured order and moves to the next path once. If every path fails it raises a single error that summarises the causes.

That error carries two flags that tell the fan-out what to do with the combined failure. If any path failed because its quota is exhausted, retrying in three seconds will fail again, so the error is marked no_retry. If the causes were only server errors or timeouts, the error is marked transient and the normal retry applies. When the fallback path produced the answer, the result records which path it came from, so a later reader of the data can tell the two collection methods apart.

LLM adapters have no fallback. A different model is a different engine, and silently answering with another one would put the wrong label on the measurement.

What is recorded per provider

There is no circuit breaker and no automatic disabling of an engine. Either one would stop an engine’s failures from being recorded, and those failures are part of what the product reports. What exists is a record.

  • Each run stores requests and tokens per engine.
  • Each run stores a summary of the web-search steps the engines reported, keyed by provider and engine.
  • Each snapshot stores, per engine, how many cells had an active surface.
  • A daily job checks the remaining quota at the SERP provider and warns when 20% or less is left.

These records are how the two adapter incidents on the incidents page were found. In one, a market code mismatch meant an adapter rejected every call for a week. In the other, a market choice was accepted and then measured in the wrong country.

Failure modes

What goes wrongWhat the system doesRegression test
429 once, then successRetried, cell succeedstest_429_is_retried_then_succeeds
429 on every tryEnds as an error cell after the last retrytest_persistent_429_ends_as_error_after_max_retries
Provider sends Retry-AfterThe sleep is lengthened; 503 is retried tootest_retry_after_lengthens_sleep_and_503_is_retried
Too many calls to one engineThe per-engine cap holdstest_per_engine_concurrency_cap_is_respected
Answer truncatedAttempt two with a doubled limittest_truncation_adds_attempt_two_with_doubled_max_tokens
The longer retry times outThe cell ends, with the longer timeout appliedtest_retry_attempt_gets_longer_read_timeout_and_timeout_ends_cell
Primary collection path failsFallback path is used, and the result records which path answeredcovered with both paths faked
Every path failsOne combined errortest_all_providers_failing_raises_combined
The search page shows no AI answerRecorded as inactive, not as an errorcovered with an empty result page
A stored market code differs from the adapter’sNormalised before the fan-outtest_fanout_passes_ko_to_engines_for_kr_brand

What I would add

The records can show that an engine has been failing for days, and nothing reads them unless a person does. The next step is a check that runs after each scheduled run and raises an alert when one engine’s share of failed cells crosses a threshold over several consecutive runs. That keeps the principle, which is to report a failure as a failure, and removes the dependence on someone opening the right table.