{"record":{"id":"08109ee1a9693c15","repo":"deepset-ai/haystack","slug":"max-effective-lines-must-be-at-least-1","errorCode":null,"errorMessage":"max_effective_lines must be at least 1.","messagePattern":"max_effective_lines must be at least 1\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/preprocessors/python_code_splitter.py","lineNumber":126,"sourceCode":"            ``oversized_factor * max_effective_lines`` triggers the line-based secondary\n            split with overlap.\n        :param strip_docstrings: If ``True``, function/method/class docstrings are moved\n            from the chunk content into ``meta[\"docstrings\"]`` (source order). The\n            module-level docstring is kept in place since it is itself a top-level unit.\n        :param preserve_class_definition: If ``True`` (default), chunks that contain class\n            members but not the class header are prefixed with the bare class signature\n            (decorators plus the ``class Foo(...):`` lines) in source order.\n        :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","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/preprocessors/python_code_splitter.py#L108-L144","documentation":"PythonCodeSplitter's __init__ requires max_effective_lines >= 1: the maximum number of effective code lines per chunk must be positive. Values below 1 make chunking impossible, so ValueError is raised.","triggerScenarios":"Calling PythonCodeSplitter(max_effective_lines=0) or negative, typically from a bad config value, a division result, or an env var defaulting to 0.","commonSituations":"Zero defaults in config files, tuning experiments setting the max below the minimum, or unit errors (lines vs tokens confusion).","solutions":["Pass max_effective_lines >= 1 and >= min_effective_lines, e.g. max_effective_lines=30.","Omit the parameter to use the default.","Clamp dynamic values: max_effective_lines=max(1, computed).","Validate the whole (min, max) pair together before construction."],"exampleFix":"// before\nPythonCodeSplitter(max_effective_lines=0)\n// after\nPythonCodeSplitter(min_effective_lines=5, max_effective_lines=30)","handlingStrategy":"validation","validationCode":"max_effective_lines = max(1, int(max_effective_lines))\nif max_effective_lines < min_effective_lines:\n    max_effective_lines = min_effective_lines","typeGuard":"def is_valid_line_range(min_l, max_l) -> bool:\n    return is_positive_int(min_l) and is_positive_int(max_l) and min_l <= max_l","tryCatchPattern":"try:\n    splitter = PythonCodeSplitter(max_effective_lines=max_lines)\nexcept ValueError as e:\n    logging.warning(\"Invalid max_effective_lines (%s), using default\", e)\n    splitter = PythonCodeSplitter()","preventionTips":["Validate (min, max) as a pair before construction.","Clamp values with max(1, value).","Keep chunk-size bounds in one config object with a single validator."],"tags":["python","validation","constructor-argument","haystack"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}