{"record":{"id":"ce3341fa61824a81","repo":"deepset-ai/haystack","slug":"secondary-split-overlap-must-be-non-negative","errorCode":null,"errorMessage":"secondary_split_overlap must be non-negative.","messagePattern":"secondary_split_overlap must be non-negative\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/preprocessors/python_code_splitter.py","lineNumber":134,"sourceCode":"        :param secondary_split_overlap: Line overlap for the secondary splitter; only used\n            in the oversized fallback. The primary AST split never adds overlap.\n        :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","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/preprocessors/python_code_splitter.py#L116-L152","documentation":"PythonCodeSplitter's __init__ validates all constructor parameters, and secondary_split_overlap (the overlap used when chunking oversized chunks via the secondary splitter) must be >= 0. A negative value would make sliding-window chunking nonsensical, so the splitter refuses to initialize. This is a fail-fast configuration check.","triggerScenarios":"Constructing PythonCodeSplitter(secondary_split_overlap=-N) for any negative integer, e.g. copying a config where overlap was computed dynamically and went negative, or sign typos like secondary_split_overlap=-20.","commonSituations":"Loading splitter settings from YAML/env/config files where the value is parsed or computed programmatically; hand-editing parameters and accidentally negating the value.","solutions":["Set secondary_split_overlap to 0 or a positive integer smaller than secondary_split_length.","If the value is computed, clamp it: max(0, computed_overlap).","If no secondary overlap is needed, omit the parameter to use the default."],"exampleFix":"// before\nsplitter = PythonCodeSplitter(secondary_split_overlap=-5)\n// after\nsplitter = PythonCodeSplitter(secondary_split_overlap=5)","handlingStrategy":"validation","validationCode":"if secondary_split_overlap is not None and secondary_split_overlap < 0:\n    raise ValueError(f'secondary_split_overlap must be >= 0, got {secondary_split_overlap}')","typeGuard":"def is_valid_overlap(v) -> bool:\n    return isinstance(v, int) and v >= 0","tryCatchPattern":"try:\n    splitter = PythonCodeSplitter(secondary_split_overlap=overlap)\nexcept ValueError as e:\n    logger.error('Invalid splitter config: %s', e)\n    splitter = PythonCodeSplitter()  # defaults","preventionTips":["Validate config values from YAML/env before constructing components.","Clamp computed overlap with max(0, value).","Write a unit test constructing the splitter with your production config."],"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"}