infiniflow/ragflow · error · TypeError
Querit API response field results.result must be an array.
Error message
Querit API response field results.result must be an array.
What it means
TypeError raised by the Querit search tool when the nested results container is a dict but its 'result' field is not a list — e.g. results.result is a dict, string, or number. This is the final shape check before items are filtered to dicts and passed to _retrieve_chunks.
Source
Thrown at agent/tools/querit.py:177
"time_range",
"country_include",
"language_include",
)
}
try:
_validate_search_inputs(**values)
payload = _build_payload(query, **values)
response_data = self._search(payload, api_key)
if not isinstance(response_data, dict):
raise TypeError("Querit API response must be a JSON object.")
result_container = response_data.get("results", {})
if not isinstance(result_container, dict):
raise TypeError("Querit API response field results must be an object.")
results = result_container.get("result", [])
if not isinstance(results, list):
raise TypeError("Querit API response field results.result must be an array.")
reference_results = [item for item in results if isinstance(item, dict)]
if reference_results:
self._retrieve_chunks(
reference_results,
get_title=lambda item: _querit_text(item.get("title")),
get_url=lambda item: _querit_text(item.get("url")),
get_content=lambda item: _querit_text(item.get("snippet")),
get_score=lambda _item: 1,
)
else:
self.set_output("formalized_content", "")
self.set_output("json", response_data)
return self.output("formalized_content")
except _QueritCanceled:
return
except (requests.RequestException, RuntimeError, TypeError, ValueError) as error:
return self._fail(_safe_error_message(error, api_key))View on GitHub (pinned to 554fb1133a)
Solutions
- Verify with curl that results.result is a JSON array ([] when empty, never null).
- If the API nulls empty arrays, treat null as [] before validation, or report the contract violation to the API owner.
- Pin the client to the API version matching the documented schema.
- Correct mocks/fixtures to use an array.
Defensive patterns
Strategy: type-guard
Validate before calling
def result_array_ok(data: dict) -> bool:
r = data.get("results", {})
return isinstance(r, dict) and isinstance(r.get("result", []), list) Type guard
def has_querit_result_list(v: Any) -> bool:
return isinstance(v, dict) and isinstance(v.get("results", {}), dict) \
and isinstance(v["results"].get("result"), list) Try / catch
try:
querit_search._invoke(query=q)
except TypeError as e:
if "results.result must be an array" in str(e):
alert_api_contract_drift(e)
raise Prevention
- Normalize null-to-[] for the result field in an adapter if the API is known to null empty arrays.
- Keep response-shape assertions in one boundary function instead of scattered isinstance checks.
When it happens
Trigger: A Querit response shaped {"results": {"result": {"0": {...}}}} (object keyed by index), {"results": {"result": null}}, or {"results": {"result": ""}} — usually from schema drift or an empty-response branch that nulls the array.
Common situations: APIs that switch empty arrays to null in some serializations; a single-result endpoint collapsing the array; hand-written mocks using a dict for result.
Related errors
- Querit API response must be a JSON object.
- Querit API response field results must be an object.
- Querit API response field results must be an array.
- Querit API response field statuses must be an array.
- 'str' object has no attribute 'get'
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/266760ff0bcb3b5a.
Report an issue: GitHub.