{"record":{"id":"216a8e57685a9804","repo":"deepset-ai/haystack","slug":"secondary-split-length-must-be-at-least-1","errorCode":null,"errorMessage":"secondary_split_length must be at least 1.","messagePattern":"secondary_split_length must be at least 1\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/preprocessors/python_code_splitter.py","lineNumber":136,"sourceCode":"        :param secondary_split_length: Lines per chunk for the secondary splitter.\n            Defaults to ``max_effective_lines`` when ``None``.\n        :raises ValueError: If any parameter is invalid (negative, zero where positive is\n            required, or ``min_effective_lines > max_effective_lines``).\n        \"\"\"\n        if min_effective_lines < 1:\n            raise ValueError(\"min_effective_lines must be at least 1.\")\n        if max_effective_lines < 1:\n            raise ValueError(\"max_effective_lines must be at least 1.\")\n        if min_effective_lines > max_effective_lines:\n            raise ValueError(\"min_effective_lines must not be greater than max_effective_lines.\")\n        if expected_chars_per_line < 1:\n            raise ValueError(\"expected_chars_per_line must be at least 1.\")\n        if oversized_factor < 1:\n            raise ValueError(\"oversized_factor must be at least 1.\")\n        if secondary_split_overlap < 0:\n            raise ValueError(\"secondary_split_overlap must be non-negative.\")\n        if secondary_split_length is not None and secondary_split_length < 1:\n            raise ValueError(\"secondary_split_length must be at least 1.\")\n\n        self.min_effective_lines = min_effective_lines\n        self.max_effective_lines = max_effective_lines\n        self.expected_chars_per_line = expected_chars_per_line\n        self.oversized_factor = oversized_factor\n        self.strip_docstrings = strip_docstrings\n        self.preserve_class_definition = preserve_class_definition\n        self.secondary_split_overlap = secondary_split_overlap\n        self.secondary_split_length = secondary_split_length\n\n    def _effective_lines(self, text: str) -> int:\n        \"\"\"Return the number of *effective lines* for ``text`` (see class docstring).\"\"\"\n        if not text:\n            return 0\n        return max(1, math.ceil(len(text) / self.expected_chars_per_line))\n\n    def _is_oversized(self, unit: \"_CodeUnit\") -> bool:\n        \"\"\"Return ``True`` if ``unit`` should trigger the secondary line-based split.\"\"\"","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/preprocessors/python_code_splitter.py#L118-L154","documentation":"PythonCodeSplitter.__init__ requires secondary_split_length, when provided, to be at least 1 character. A length of 0 or negative cannot produce any chunks, so initialization fails fast with this ValueError.","triggerScenarios":"PythonCodeSplitter(secondary_split_length=0), a negative value, or passing None-derived values into arithmetic that yields < 1.","commonSituations":"Config-driven pipelines where secondary_split_length comes from user input or a computed expression that resolves to 0; misunderstanding that None means 'use default' while 0 means 'invalid'.","solutions":["Set secondary_split_length to a positive integer (e.g. 500-1000).","If the value is dynamic, validate/clamp before constructing: max(1, n).","Pass None instead of 0 to fall back to the default secondary length."],"exampleFix":"// before\nsplitter = PythonCodeSplitter(secondary_split_length=0)\n// after\nsplitter = PythonCodeSplitter(secondary_split_length=512)","handlingStrategy":"validation","validationCode":"if secondary_split_length is not None and secondary_split_length < 1:\n    raise ValueError(f'secondary_split_length must be >= 1, got {secondary_split_length}')","typeGuard":"def is_valid_length(v) -> bool:\n    return v is None or (isinstance(v, int) and v >= 1)","tryCatchPattern":"try:\n    splitter = PythonCodeSplitter(secondary_split_length=cfg.get('secondary_split_length'))\nexcept ValueError as e:\n    logger.error('Invalid secondary_split_length: %s', e)\n    splitter = PythonCodeSplitter()","preventionTips":["Use None (not 0) to mean 'use default'.","Sanitize numeric config inputs at load time.","Document valid ranges for splitter parameters in your config schema."],"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"}