Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(exa): fall back to highlights/summary when text is missing (#42213)

Waqas Ahmed4a847ac936a0
diff --git a/litellm/llms/exa_ai/search/transformation.py b/litellm/llms/exa_ai/search/transformation.py
index 022622d7af7..cd904e493f2 100644
--- a/litellm/llms/exa_ai/search/transformation.py
+++ b/litellm/llms/exa_ai/search/transformation.py
@@ -165,6 +165,8 @@ class ExaAISearchConfig(BaseSearchConfig):
- results[].title → SearchResult.title
- results[].url → SearchResult.url
- results[].text → SearchResult.snippet
+ - results[].highlights → SearchResult.snippet (fallback when "text" is absent)
+ - results[].summary → SearchResult.snippet (fallback when "text" and "highlights" are absent)
- results[].publishedDate → SearchResult.date
- No last_updated field in Exa AI response (set to None)
@@ -183,7 +185,10 @@ class ExaAISearchConfig(BaseSearchConfig):
search_result = SearchResult(
title=result.get("title", ""),
url=result.get("url", ""),
- snippet=result.get("text", ""), # Exa AI uses "text" for content
+ snippet=result.get("text")
+ or "\n\n".join(result.get("highlights") or [])
+ or result.get("summary")
+ or "",
date=result.get("publishedDate"), # ISO 8601 datetime string
last_updated=None, # Exa AI doesn't provide last_updated in response
)
diff --git a/tests/unit/llms/exa_ai/__init__.py b/tests/unit/llms/exa_ai/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/unit/llms/exa_ai/search/__init__.py b/tests/unit/llms/exa_ai/search/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/unit/llms/exa_ai/search/test_transformation.py b/tests/unit/llms/exa_ai/search/test_transformation.py
new file mode 100644
index 00000000000..5e5eb24f23b
--- /dev/null
+++ b/tests/unit/llms/exa_ai/search/test_transformation.py
@@ -0,0 +1,33 @@
+from typing import Final
+from unittest.mock import Mock
+
+import httpx
+import pytest
+
+from litellm.llms.exa_ai.search.transformation import ExaAISearchConfig
+
+
+ ("content_fields", "expected_snippet"),
+ [
+ ({"text": "full text"}, "full text"),
+ ({"highlights": ["first highlight", "second highlight"]}, "first highlight\n\nsecond highlight"),
+ ({"summary": "a summary"}, "a summary"),
+ ({"text": "full text", "highlights": ["a highlight"], "summary": "a summary"}, "full text"),
+ ({"highlights": ["a highlight"], "summary": "a summary"}, "a highlight"),
+ ({"text": "", "highlights": ["a highlight"]}, "a highlight"),
+ ({"highlights": [], "summary": "a summary"}, "a summary"),
+ ({}, ""),
+ ],
+)
+def test_transform_search_response_snippet_falls_back_through_content_modes(
+ content_fields: dict[str, str | list[str]], expected_snippet: str
+):
+ raw_response: Final = httpx.Response(
+ 200,
+ json={"results": [{"title": "Title", "url": "https://example.com", **content_fields}]},
+ )
+
+ response: Final = ExaAISearchConfig().transform_search_response(raw_response, logging_obj=Mock())
+
+ assert response.results[0].snippet == expected_snippet