{"record":{"id":"ada833fe3813423b","repo":"deepset-ai/haystack","slug":"split-length-must-be-at-least-1-character","errorCode":null,"errorMessage":"Split length must be at least 1 character.","messagePattern":"Split length must be at least 1 character\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/preprocessors/recursive_splitter.py","lineNumber":115,"sourceCode":"        self.tiktoken_tokenizer: \"tiktoken.Encoding\" | None = None\n        self._is_warmed_up = False\n\n    def warm_up(self) -> None:\n        \"\"\"\n        Warm up the sentence tokenizer and tiktoken tokenizer if needed.\n        \"\"\"\n        if self._is_warmed_up:\n            return\n        if \"sentence\" in self.separators:\n            self.nltk_tokenizer = self._get_custom_sentence_tokenizer(self.sentence_splitter_params)\n        if self.split_units == \"token\":\n            tiktoken_imports.check()\n            self.tiktoken_tokenizer = tiktoken.get_encoding(\"o200k_base\")\n        self._is_warmed_up = True\n\n    def _check_params(self) -> None:\n        if self.split_length < 1:\n            raise ValueError(\"Split length must be at least 1 character.\")\n        if self.split_overlap < 0:\n            raise ValueError(\"split_overlap must be greater than or equal to 0.\")\n        if self.split_overlap >= self.split_length:\n            raise ValueError(\"Overlap cannot be greater than or equal to the chunk size.\")\n        if not all(isinstance(separator, str) for separator in self.separators):\n            raise ValueError(\"All separators must be strings.\")\n\n    @staticmethod\n    def _get_custom_sentence_tokenizer(sentence_splitter_params: dict[str, Any]) -> Any:\n        from haystack.components.preprocessors.sentence_tokenizer import SentenceSplitter\n\n        return SentenceSplitter(**sentence_splitter_params)\n\n    def _split_chunk(self, current_chunk: str) -> tuple[str, str]:\n        \"\"\"\n        Splits a chunk based on the split_length and split_units attribute.\n\n        :param current_chunk: The current chunk to be split.","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/preprocessors/recursive_splitter.py#L97-L133","documentation":"RecursiveSplitter validates its parameters via _check_params (called from __init__); split_length must be >= 1. A split_length of 0 or negative would produce empty or infinitely-looping chunks, so construction is rejected.","triggerScenarios":"RecursiveSplitter(split_length=0) or negative, typically from a config file value of 0, a computed value, or confusing split_length units (chars/tokens) and passing a percentage or factor.","commonSituations":"YAML/env pipeline configs where split_length was left at 0; swapping splitters (e.g. from a component that used a fraction parameter) and reusing old values.","solutions":["Set split_length to a positive integer appropriate to the unit (characters or tokens per chunk, e.g. 200-2000).","Clamp dynamic values: max(1, requested).","Verify the config key actually maps to split_length and not another parameter."],"exampleFix":"// before\nsplitter = RecursiveSplitter(split_length=0)\n// after\nsplitter = RecursiveSplitter(split_length=500)","handlingStrategy":"validation","validationCode":"if split_length < 1:\n    raise ValueError(f'split_length must be >= 1, got {split_length}')","typeGuard":"def is_valid_split_length(v) -> bool:\n    return isinstance(v, int) and v >= 1","tryCatchPattern":"try:\n    splitter = RecursiveSplitter(split_length=n)\nexcept ValueError as e:\n    logger.error('Invalid split_length: %s', e)\n    splitter = RecursiveSplitter(split_length=200)","preventionTips":["Validate config-driven split_length before building pipelines.","Never pass 0 as a 'disabled' sentinel; omit the parameter instead.","Add construction smoke tests for your production splitter configs."],"tags":["python","validation","constructor-argument","haystack"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}