{"record":{"id":"a896a54b49dc8376","repo":"infiniflow/ragflow","slug":"literal-error","errorCode":"literal_error","errorMessage":"Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'","messagePattern":"Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'","errorType":"validation","errorClass":"PydanticCustomError","httpStatus":null,"severity":"error","filePath":"api/utils/validation_utils.py","lineNumber":837,"sourceCode":"                    invalid.append(\"pipeline_id\")\n                raise PydanticCustomError(\n                    \"dependency_error\",\n                    \"parser_id provided → disallowed fields present: {fields}\",\n                    {\"fields\": \", \".join(invalid)},\n                )\n        return self\n\n    @field_validator(\"chunk_method\", mode=\"wrap\")\n    @classmethod\n    def validate_chunk_method(cls, v: Any, handler, info: ValidationInfo) -> Any:\n        \"\"\"Wrap validation to unify error messages, including type errors (e.g. list).\"\"\"\n        allowed = {\"naive\", \"book\", \"email\", \"laws\", \"manual\", \"one\", \"paper\", \"picture\", \"presentation\", \"qa\", \"table\", \"tag\", \"resume\"}\n        error_msg = \"Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'\"\n        try:\n            # Run inner validation (type checking)\n            result = handler(v)\n        except Exception:\n            raise PydanticCustomError(\"literal_error\", error_msg)\n            # Omitted field: handler won't be invoked (wrap still gets value); None treated as explicit invalid\n        if not result and not info.data.get(\"pipeline_id\", None):\n            raise PydanticCustomError(\"literal_error\", error_msg)\n        # After handler, enforce enumeration\n        if result and result not in allowed:\n            raise PydanticCustomError(\"literal_error\", error_msg)\n        return result\n\n\nclass UpdateDatasetReq(CreateDatasetReq):\n    \"\"\"Request model for updating a dataset.\"\"\"\n\n    dataset_id: Annotated[str, Field(...)]\n    name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(default=\"\")]\n    pagerank: Annotated[int, Field(default=0, ge=0, le=100)]\n    language: Annotated[str | None, Field(default=None, max_length=32)]\n    connectors: Annotated[list[dict[str, Any]], Field(default_factory=list)]\n","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/utils/validation_utils.py#L819-L855","documentation":"Wrap-mode validator on chunk_method (CreateDatasetReq) that unifies all failures into one literal_error message. This first raise site fires when the inner handler itself throws — i.e. the value's type does not match the field's Literal type — such as passing a list, dict, number, or a string not in the Literal enum. The catch-all converts Pydantic's native literal_error/typed errors into the fixed enumeration message.","triggerScenarios":"\"chunk_method\": [\"naive\"] (list instead of string), \"chunk_method\": 123, or \"chunk_method\": \"audio\" — handler(v) fails type/enum validation and the except branch raises the unified literal_error.","commonSituations":"JSON bodies where an array wraps the value; numbers coerced from a select control; new chunk methods used against an older API whose Literal enum lacks them.","solutions":["Send chunk_method as a plain string exactly equal to one of: naive, book, email, laws, manual, one, paper, picture, presentation, qa, table, tag, resume.","Unwrap arrays and stringify numbers client-side before sending.","If you need pipeline mode, omit chunk_method entirely and send parse_type+pipeline_id instead."],"exampleFix":"# before\n{\"chunk_method\": [\"naive\"]}\n\n# after\n{\"chunk_method\": \"naive\"}","handlingStrategy":"type-guard","validationCode":"DATASET_CHUNK_METHODS = {\"naive\",\"book\",\"email\",\"laws\",\"manual\",\"one\",\"paper\",\"picture\",\"presentation\",\"qa\",\"table\",\"tag\",\"resume\"}\n\ndef assert_chunk_method(v) -> str:\n    if not isinstance(v, str) or v not in DATASET_CHUNK_METHODS:\n        raise TypeError(f\"chunk_method must be one of {sorted(DATASET_CHUNK_METHODS)}, got {v!r}\")\n    return v","typeGuard":"const CHUNK_METHODS = [\"naive\",\"book\",\"email\",\"laws\",\"manual\",\"one\",\"paper\",\"picture\",\"presentation\",\"qa\",\"table\",\"tag\",\"resume\"] as const;\ntype ChunkMethod = typeof CHUNK_METHODS[number];\nconst isChunkMethod = (v: unknown): v is ChunkMethod =>\n  typeof v === \"string\" && (CHUNK_METHODS as readonly string[]).includes(v);","tryCatchPattern":"try:\n    api.create_dataset(body)\nexcept ValidationError as e:\n    if any(err[\"type\"] == \"literal_error\" and \"chunk_method\" in str(e) for err in e.errors()):\n        body[\"chunk_method\"] = assert_chunk_method(str(body[\"chunk_method\"]).strip())\n        api.create_dataset(body)","preventionTips":["Type the field as a string literal union / enum in the client.","Unwrap arrays and stringify values before serializing.","Keep the enum list in a shared constant updated with each RAGFlow upgrade."],"tags":["chunking","literal-validation","pydantic","type-mismatch"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}