deepset-ai/haystack · error · ValueError
max_effective_lines must be at least 1.
Error message
max_effective_lines must be at least 1.
What it means
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.
Source
Thrown at haystack/components/preprocessors/python_code_splitter.py:126
``oversized_factor * max_effective_lines`` triggers the line-based secondary
split with overlap.
:param strip_docstrings: If ``True``, function/method/class docstrings are moved
from the chunk content into ``meta["docstrings"]`` (source order). The
module-level docstring is kept in place since it is itself a top-level unit.
:param preserve_class_definition: If ``True`` (default), chunks that contain class
members but not the class header are prefixed with the bare class signature
(decorators plus the ``class Foo(...):`` lines) in source order.
:param secondary_split_overlap: Line overlap for the secondary splitter; only used
in the oversized fallback. The primary AST split never adds overlap.
:param secondary_split_length: Lines per chunk for the secondary splitter.
Defaults to ``max_effective_lines`` when ``None``.
:raises ValueError: If any parameter is invalid (negative, zero where positive is
required, or ``min_effective_lines > max_effective_lines``).
"""
if min_effective_lines < 1:
raise ValueError("min_effective_lines must be at least 1.")
if max_effective_lines < 1:
raise ValueError("max_effective_lines must be at least 1.")
if min_effective_lines > max_effective_lines:
raise ValueError("min_effective_lines must not be greater than max_effective_lines.")
if expected_chars_per_line < 1:
raise ValueError("expected_chars_per_line must be at least 1.")
if oversized_factor < 1:
raise ValueError("oversized_factor must be at least 1.")
if secondary_split_overlap < 0:
raise ValueError("secondary_split_overlap must be non-negative.")
if secondary_split_length is not None and secondary_split_length < 1:
raise ValueError("secondary_split_length must be at least 1.")
self.min_effective_lines = min_effective_lines
self.max_effective_lines = max_effective_lines
self.expected_chars_per_line = expected_chars_per_line
self.oversized_factor = oversized_factor
self.strip_docstrings = strip_docstrings
self.preserve_class_definition = preserve_class_definition
self.secondary_split_overlap = secondary_split_overlapView on GitHub (pinned to e318778c9b)
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.
Example fix
// before PythonCodeSplitter(max_effective_lines=0) // after PythonCodeSplitter(min_effective_lines=5, max_effective_lines=30)
Defensive patterns
Strategy: validation
Validate before calling
max_effective_lines = max(1, int(max_effective_lines))
if max_effective_lines < min_effective_lines:
max_effective_lines = min_effective_lines Type guard
def is_valid_line_range(min_l, max_l) -> bool:
return is_positive_int(min_l) and is_positive_int(max_l) and min_l <= max_l Try / catch
try:
splitter = PythonCodeSplitter(max_effective_lines=max_lines)
except ValueError as e:
logging.warning("Invalid max_effective_lines (%s), using default", e)
splitter = PythonCodeSplitter() Prevention
- 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.
When it happens
Trigger: Calling PythonCodeSplitter(max_effective_lines=0) or negative, typically from a bad config value, a division result, or an env var defaulting to 0.
Common situations: Zero defaults in config files, tuning experiments setting the max below the minimum, or unit errors (lines vs tokens confusion).
Related errors
- header_split_levels must be a non-empty list.
- min_effective_lines must be at least 1.
- expected_chars_per_line must be at least 1.
- oversized_factor must be at least 1.
- secondary_split_overlap must be non-negative.
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/08109ee1a9693c15.
Report an issue: GitHub.