infiniflow/ragflow · error · PydanticCustomError
literal_error
literal_error
Error message
Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'
What it means
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.
Source
Thrown at api/utils/validation_utils.py:837
invalid.append("pipeline_id")
raise PydanticCustomError(
"dependency_error",
"parser_id provided → disallowed fields present: {fields}",
{"fields": ", ".join(invalid)},
)
return self
@field_validator("chunk_method", mode="wrap")
@classmethod
def validate_chunk_method(cls, v: Any, handler, info: ValidationInfo) -> Any:
"""Wrap validation to unify error messages, including type errors (e.g. list)."""
allowed = {"naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag", "resume"}
error_msg = "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'"
try:
# Run inner validation (type checking)
result = handler(v)
except Exception:
raise PydanticCustomError("literal_error", error_msg)
# Omitted field: handler won't be invoked (wrap still gets value); None treated as explicit invalid
if not result and not info.data.get("pipeline_id", None):
raise PydanticCustomError("literal_error", error_msg)
# After handler, enforce enumeration
if result and result not in allowed:
raise PydanticCustomError("literal_error", error_msg)
return result
class UpdateDatasetReq(CreateDatasetReq):
"""Request model for updating a dataset."""
dataset_id: Annotated[str, Field(...)]
name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(default="")]
pagerank: Annotated[int, Field(default=0, ge=0, le=100)]
language: Annotated[str | None, Field(default=None, max_length=32)]
connectors: Annotated[list[dict[str, Any]], Field(default_factory=list)]
View on GitHub (pinned to 554fb1133a)
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.
Example fix
# before
{"chunk_method": ["naive"]}
# after
{"chunk_method": "naive"} Defensive patterns
Strategy: type-guard
Validate before calling
DATASET_CHUNK_METHODS = {"naive","book","email","laws","manual","one","paper","picture","presentation","qa","table","tag","resume"}
def assert_chunk_method(v) -> str:
if not isinstance(v, str) or v not in DATASET_CHUNK_METHODS:
raise TypeError(f"chunk_method must be one of {sorted(DATASET_CHUNK_METHODS)}, got {v!r}")
return v Type guard
const CHUNK_METHODS = ["naive","book","email","laws","manual","one","paper","picture","presentation","qa","table","tag","resume"] as const; type ChunkMethod = typeof CHUNK_METHODS[number]; const isChunkMethod = (v: unknown): v is ChunkMethod => typeof v === "string" && (CHUNK_METHODS as readonly string[]).includes(v);
Try / catch
try:
api.create_dataset(body)
except ValidationError as e:
if any(err["type"] == "literal_error" and "chunk_method" in str(e) for err in e.errors()):
body["chunk_method"] = assert_chunk_method(str(body["chunk_method"]).strip())
api.create_dataset(body) Prevention
- 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.
When it happens
Trigger: "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.
Common situations: 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.
Related errors
- format_invalid
- {} must be an array, but its type is {}
- The input of List Operations should be an array.
- [VariableAggregator] variables of group `{g.get('group_name'
- Invalid base64 encoding: {str(e)}
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/a896a54b49dc8376.
Report an issue: GitHub.