{"record":{"id":"3387d0e7e83631a9","repo":"infiniflow/ragflow","slug":"querit-chunks-per-doc-must-be-an-integer-from-1-to","errorCode":null,"errorMessage":"Querit chunks_per_doc must be an integer from 1 to 3.","messagePattern":"Querit chunks_per_doc must be an integer from 1 to 3\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/tools/querit.py","lineNumber":408,"sourceCode":"    if \"results\" in response_data and not isinstance(response_data[\"results\"], list):\n        raise TypeError(\"Querit API response field results must be an array.\")\n    if \"statuses\" in response_data and not isinstance(response_data[\"statuses\"], list):\n        raise TypeError(\"Querit API response field statuses must be an array.\")\n\n\ndef _validate_search_inputs(\n    count: Any,\n    chunks_per_doc: Any,\n    time_range: Any,\n    site_include: Any,\n    site_exclude: Any,\n    country_include: Any,\n    language_include: Any,\n) -> None:\n    if type(count) is not int or count < 1:\n        raise ValueError(\"Querit count must be an integer greater than or equal to 1.\")\n    if chunks_per_doc is not None and (type(chunks_per_doc) is not int or not 1 <= chunks_per_doc <= 3):\n        raise ValueError(\"Querit chunks_per_doc must be an integer from 1 to 3.\")\n    if type(time_range) is not str:\n        raise ValueError(\"Querit time_range must be a string.\")\n    if time_range and not TIME_RANGE_PATTERN.fullmatch(time_range):\n        raise ValueError(\"Querit time_range must use dN, wN, mN, yN, or YYYY-MM-DDtoYYYY-MM-DD.\")\n    for name, value in (\n        (\"site_include\", site_include),\n        (\"site_exclude\", site_exclude),\n        (\"country_include\", country_include),\n        (\"language_include\", language_include),\n    ):\n        if not isinstance(value, list) or any(not isinstance(item, str) for item in value):\n            raise ValueError(f\"Querit {name} must be an array of strings.\")\n\n\ndef _safe_error_message(error: Exception, api_key: str) -> str:\n    message = str(error) or error.__class__.__name__\n    return message.replace(api_key, \"[REDACTED]\") if api_key else message\n","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/tools/querit.py#L390-L426","documentation":"ValueError from _validate_search_inputs(): the optional 'chunks_per_doc' parameter must be None or a strict int in [1, 3]. Floats, strings, booleans, zero, or values above 3 raise. It is the only search input that may be omitted (None passes).","triggerScenarios":"chunks_per_doc=0 or 4 (outside 1..3), chunks_per_doc=2.0 (float), chunks_per_doc=\"2\" (string), or a workflow binding None-alternatives like 0 instead of omitting the field.","commonSituations":"Users asking for 'more chunks per document' and setting 5; UI numeric steppers emitting floats; parameter templates defaulting to 0 to mean 'unset'.","solutions":["Use an integer 1, 2, or 3 — or pass None / omit the parameter entirely.","Clamp in your caller: chunks_per_doc = None if not value else max(1, min(3, int(value))).","Use 0-to-mean-unset templates remapped to None before the call."],"exampleFix":"# before\nchunks_per_doc = 5  # ValueError\n\n# after\nchunks_per_doc = 3 if value > 3 else (value or None)  # capped at 3, None when unset","handlingStrategy":"validation","validationCode":"def safe_chunks_per_doc(v):\n    if v in (None, 0, \"\", []):\n        return None\n    return max(1, min(3, int(v)))","typeGuard":"def is_valid_chunks_per_doc(v) -> bool:\n    return v is None or (type(v) is int and 1 <= v <= 3)","tryCatchPattern":"try:\n    querit_search._invoke(query=q, chunks_per_doc=c)\nexcept ValueError as e:\n    if \"chunks_per_doc\" in str(e):\n        c = None; querit_search._invoke(query=q, chunks_per_doc=c)\n    raise","preventionTips":["Clamp to 1..3 or omit the parameter (None is valid).","Remap '0 means unset' template defaults to None.","Coerce stepper/UI floats with int()."],"tags":["validation","input","querit","range"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}