{"record":{"id":"266760ff0bcb3b5a","repo":"infiniflow/ragflow","slug":"querit-api-response-field-results-result-must-be-a","errorCode":null,"errorMessage":"Querit API response field results.result must be an array.","messagePattern":"Querit API response field results\\.result must be an array\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"agent/tools/querit.py","lineNumber":177,"sourceCode":"                \"time_range\",\n                \"country_include\",\n                \"language_include\",\n            )\n        }\n\n        try:\n            _validate_search_inputs(**values)\n            payload = _build_payload(query, **values)\n            response_data = self._search(payload, api_key)\n            if not isinstance(response_data, dict):\n                raise TypeError(\"Querit API response must be a JSON object.\")\n\n            result_container = response_data.get(\"results\", {})\n            if not isinstance(result_container, dict):\n                raise TypeError(\"Querit API response field results must be an object.\")\n            results = result_container.get(\"result\", [])\n            if not isinstance(results, list):\n                raise TypeError(\"Querit API response field results.result must be an array.\")\n\n            reference_results = [item for item in results if isinstance(item, dict)]\n            if reference_results:\n                self._retrieve_chunks(\n                    reference_results,\n                    get_title=lambda item: _querit_text(item.get(\"title\")),\n                    get_url=lambda item: _querit_text(item.get(\"url\")),\n                    get_content=lambda item: _querit_text(item.get(\"snippet\")),\n                    get_score=lambda _item: 1,\n                )\n            else:\n                self.set_output(\"formalized_content\", \"\")\n            self.set_output(\"json\", response_data)\n            return self.output(\"formalized_content\")\n        except _QueritCanceled:\n            return\n        except (requests.RequestException, RuntimeError, TypeError, ValueError) as error:\n            return self._fail(_safe_error_message(error, api_key))","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/tools/querit.py#L159-L195","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"def result_array_ok(data: dict) -> bool:\n    r = data.get(\"results\", {})\n    return isinstance(r, dict) and isinstance(r.get(\"result\", []), list)","typeGuard":"def has_querit_result_list(v: Any) -> bool:\n    return isinstance(v, dict) and isinstance(v.get(\"results\", {}), dict) \\\n        and isinstance(v[\"results\"].get(\"result\"), list)","tryCatchPattern":"try:\n    querit_search._invoke(query=q)\nexcept TypeError as e:\n    if \"results.result must be an array\" in str(e):\n        alert_api_contract_drift(e)\n    raise","preventionTips":["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."],"tags":["api","json","response-validation","querit"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}