infiniflow/ragflow · error · TypeError

Querit API response field results must be an array.

Error message

Querit API response field results must be an array.

What it means

TypeError from _validate_contents_response(): when the response object contains a 'results' key, its value must be an array (list). The key is optional, but if present it cannot be a dict, string, or null.

Source

Thrown at agent/tools/querit.py:391

    if not isinstance(urls, list) or not 1 <= len(urls) <= 10 or any(not isinstance(url, str) or not url.strip() for url in urls):
        raise ValueError("Querit urls must contain between 1 and 10 non-empty strings.")
    for url in urls:
        parsed = urlparse(url)
        if parsed.scheme not in {"http", "https"} or not parsed.netloc:
            raise ValueError("Querit urls must be absolute HTTP or HTTPS URLs.")
    if format not in QUERIT_CONTENT_FORMATS:
        raise ValueError("Querit format must be text, markdown, or html.")
    if type(crawl_timeout) is not int or not 1 <= crawl_timeout <= 60:
        raise ValueError("Querit crawl_timeout must be an integer from 1 to 60.")
    if type(extras_meta) is not bool:
        raise ValueError("Querit extras_meta must be a boolean.")


def _validate_contents_response(response_data: Any) -> None:
    if not isinstance(response_data, dict):
        raise TypeError("Querit API response must be a JSON object.")
    if "results" in response_data and not isinstance(response_data["results"], list):
        raise TypeError("Querit API response field results must be an array.")
    if "statuses" in response_data and not isinstance(response_data["statuses"], list):
        raise TypeError("Querit API response field statuses must be an array.")


def _validate_search_inputs(
    count: Any,
    chunks_per_doc: Any,
    time_range: Any,
    site_include: Any,
    site_exclude: Any,
    country_include: Any,
    language_include: Any,
) -> None:
    if type(count) is not int or count < 1:
        raise ValueError("Querit count must be an integer greater than or equal to 1.")
    if chunks_per_doc is not None and (type(chunks_per_doc) is not int or not 1 <= chunks_per_doc <= 3):
        raise ValueError("Querit chunks_per_doc must be an integer from 1 to 3.")
    if type(time_range) is not str:

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Verify with curl that 'results' (when present) is a JSON array.
  2. Treat null as absent in an adapter layer if the API documents that, then re-validate.
  3. Pin the API version matching the array contract.
  4. Fix test fixtures.
Defensive patterns

Strategy: type-guard

Validate before calling

def contents_results_ok(data: dict) -> bool:
    return "results" not in data or isinstance(data["results"], list)

Type guard

from typing import Any
def has_list_results(v: Any) -> bool:
    return not isinstance(v, dict) or "results" not in v or isinstance(v["results"], list)

Try / catch

try:
    querit_contents._invoke(urls=urls)
except TypeError as e:
    if "results must be an array" in str(e):
        alert_api_contract_drift(e)
    raise

Prevention

When it happens

Trigger: A contents response like {"results": {"docs": [...]}} or {"results": null} — schema drift or an error branch reusing the field with a different type.

Common situations: APIs collapsing the array to null for empty crawls; newer API versions nesting results under an object; stale mocks with dict-shaped results.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/f88f4f8bf2967a21. Report an issue: GitHub.