Expander errors
Common error signatures
Errors from QueryExpander fall into three categories: API connectivity failures, malformed LLM responses, and authentication problems.
- Anthropic API errors — network timeouts, rate limits, or HTTP errors raised when
expand()orexpand_async()calls Claude Haiku. These typically appear as SDK-level exceptions such asanthropic.APIConnectionError,anthropic.RateLimitError, oranthropic.APIStatusError. - JSON parse failures —
json.JSONDecodeErrorraised when the model returns a response that isn't a valid JSON array. The system prompt instructs the model to return only a JSON array of strings; any deviation (markdown fences, explanatory text, empty response) causes this failure. - Authentication errors —
anthropic.AuthenticationErrorwhen theapi_keyargument isNoneand noANTHROPIC_API_KEYenvironment variable is set, or when the provided key is invalid.
Where errors originate
All errors originate in src/attune_rag/expander.py. The two entry points are:
QueryExpander.expand(query)— synchronous path; raises synchronously on API or parse failure.QueryExpander.expand_async(query)— async path; the same failure modes apply, but exceptions are raised inside the coroutine and must be awaited to surface.
Both methods share the same LLM call and JSON parsing logic, so a failure in one likely reproduces in the other.
How to diagnose
-
Check the exception type first. The type tells you which layer failed:
- An
anthropic.AuthenticationErrormeans the API key is missing or wrong — verify theapi_keyargument passed toQueryExpander.__init__or theANTHROPIC_API_KEYenvironment variable. - An
anthropic.RateLimitErrororanthropic.APIConnectionErrormeans the Anthropic API was unreachable or throttled — retry with backoff or check your account limits. - A
json.JSONDecodeErrormeans the model returned something other than a plain JSON array. Log the raw response text to see what the model actually returned.
- An
-
Inspect the raw model response. If you see a
json.JSONDecodeError, the model ignored the system prompt constraint ("Return ONLY the JSON array — no explanation, no markdown fences"). Capture thecontentfield of the API response before parsing to confirm what text triggered the failure. -
Verify caching behavior.
QueryExpanderaccepts acache=Trueparameter. If you are seeing stale or unexpected expansions rather than an exception, confirm whether caching is returning a previously stored result instead of making a fresh API call. -
Confirm the model identifier. The default model is
claude-haiku-4-5-20251001. If you pass a custommodelstring to__init__and receive ananthropic.NotFoundErroror similar, verify the model name is correct and available on your account.
Source files
src/attune_rag/expander.py
Tags: expander, hybrid-retrieval, recall, claude, haiku