infiniflow/ragflow · error · PydanticCustomError

string_too_long

string_too_long

Error message

Parser config exceeds size limit (max 65,535 characters). Current size: {actual}

What it means

Validator that serializes parser_config to JSON and enforces the 65,535-character budget (matching the DB column limit for the config blob). If model_dump_json() produces more than 65,535 characters it raises string_too_long with the actual size. This guards against truncation or insert failures deeper in the storage layer.

Source

Thrown at api/utils/validation_utils.py:756

        Implements a two-stage validation workflow:
        1. Null check - bypass validation for empty configurations
        2. Model serialization - convert Pydantic model to JSON string
        3. Size verification - enforce maximum allowed payload size

        Args:
            v (ParserConfig | None): Raw parser configuration object

        Returns:
            ParserConfig | None: Validated configuration object

        Raises:
            PydanticCustomError: When serialized JSON exceeds 65,535 characters
        """
        if v is None:
            return None

        if (json_str := v.model_dump_json()) and len(json_str) > 65535:
            raise PydanticCustomError("string_too_long", "Parser config exceeds size limit (max 65,535 characters). Current size: {actual}", {"actual": len(json_str)})
        return v

    @field_validator("pipeline_id", mode="after")
    @classmethod
    def validate_pipeline_id(cls, v: str | None) -> str | None:
        """Validate pipeline_id as 32-char lowercase hex string if provided.

        Rules:
        - None or empty string: treat as None (not set)
        - Must be exactly length 32
        - Must contain only hex digits (0-9a-fA-F); normalized to lowercase
        """
        if v is None:
            return None
        if v == "":
            return None
        if len(v) != 32:
            raise PydanticCustomError("format_invalid", "pipeline_id must be 32 hex characters")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Trim the oversized value — usually the raptor prompt or a page-range/manual chunk list — until the serialized config is under 65,535 chars.
  2. Compute json.dumps(config, separators=(',',':')) length client-side before sending to fail fast.
  3. Move large prompts into the model/LLM configuration layer rather than embedding them in parser_config.

Example fix

# before
parser_config = {"raptor": {"prompt": HUGE_100K_CHAR_PROMPT, ...}}

# after
assert len(json.dumps(parser_config, separators=(',',':'))) <= 65535
resp = client.post("/api/v1/datasets", json={"parser_config": parser_config, ...})
Defensive patterns

Strategy: validation

Validate before calling

import json

MAX = 65535

def check_parser_config(cfg: dict | None) -> None:
    if cfg is None:
        return
    size = len(json.dumps(cfg, separators=(",", ":"), ensure_ascii=False))
    if size > MAX:
        raise ValueError(f"parser_config serializes to {size} chars (max {MAX}); trim raptor prompts or page ranges")

Try / catch

try:
    api.create_dataset(payload)
except ValidationError as e:
    if any(err["type"] == "string_too_long" and "Parser config" in str(err) for err in e.errors()):
        trim_raptor_prompt(payload)
        api.create_dataset(payload)

Prevention

When it happens

Trigger: POST/PUT dataset with a parser_config containing huge values — e.g. a very long 'raptor' prompt, thousands of page ranges, or an embedded knowledge graph instruction block — whose serialized JSON exceeds 64 KiB.

Common situations: Custom LLM prompts for RAPTOR/GraphRAKER pasted into parser_config.raptor.prompt; auto-generated configs with unbounded lists; config templates inherited from another system with large embedded stopwords/dictionaries.

Related errors


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