Back to Signal Feed
CodeTracked since May 18, 2026

Guard empty LLM responses to prevent adapter crashes

A single correctness-focused change adds empty-response checks before indexing `response.choices[0]` in 16 callsites across multiple `llama_index` LLM integrations, replacing unsafe direct access that could crash with `IndexError`/`AttributeError` when providers return no choices (issue #21337).

llama_indexLLM adaptersresponse.choicesempty response

What Happened

  • A single correctness-focused change adds empty-response checks before indexing `response.choices[0]` in 16 callsites across multiple `llama_index` LLM integrations, replacing unsafe direct access that could crash with `IndexError`/`AttributeError` when providers return no choices (issue #21337).
  • A single correctness-focused change adds empty-response checks before indexing `response.choices[0]` in 16 callsites across multiple `llama_index` LLM integrations, replacing unsafe direct access that could crash with `IndexError`/`AttributeError` when providers return no choices (issue #21337).
  • 1 evidence item attached for review.

What is Different

Before

Scattered source updates, isolated context, and manual follow-up across multiple feeds.

Now

Implemented a concrete safety guard pattern (`if not response.choices`) across all identified unguarded response-access sites, so empty-choice provider replies are handled as explicit validation errors instead of implicit runtime failures.

Why Track This

Why It Matters

Applications and teams using these `llama_index` providers will fail more predictably when an upstream model returns an empty completion, which reduces production incidents from ambiguous crashes and makes error handling/retries easier to automate. The patch changes 16 direct `choices[0]` dereferences to explicit checks and converts failures into a clear `ValueError`, but operators should watch for two adapters (Azure Inference and MistralAI) that still show incomplete pact proof status and ensure downstream code handles the new error type consistently.

Impact

Applications and teams using these `llama_index` providers will fail more predictably when an upstream model returns an empty completion, which reduces production incidents from ambiguous crashes and makes error handling/retries easier to automate. The patch changes 16 direct `choices[0]` dereferences to explicit checks and converts failures into a clear `ValueError`, but operators should watch for two adapters (Azure Inference and MistralAI) that still show incomplete pact proof status and ensure downstream code handles the new error type consistently.

What To Watch Next

  • Watch whether llama_index becomes a repeated pattern.
  • Track follow-up changes around AI Debugging and Error Localization.
  • Compare future signals against this evidence trail.
  • Re-check risk flags: watch_for_client_code_missing_valueerror_handling, monitor_providers_emitting_empty_choices_under_load.
Open Topic TimelineOpen Technical EventOpen Original Sourcewatch_for_client_code_missing_valueerror_handling / monitor_providers_emitting_empty_choices_under_load / track_azure_and_mistralai_contract_proof_resolution

Supporting Evidence