deepset-ai/haystack · error · ValueError
min_effective_lines must not be greater than max_effective_l
Error message
min_effective_lines must not be greater than max_effective_lines.
What it means
PythonCodeSplitter's __init__ enforces min_effective_lines <= max_effective_lines. An inverted range is logically invalid for bounding chunk sizes, so ValueError is raised.
Source
Thrown at haystack/components/preprocessors/python_code_splitter.py:128
: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_overlap
self.secondary_split_length = secondary_split_length
View on GitHub (pinned to e318778c9b)
Solutions
- Swap or correct the values so min <= max.
- Add a caller-side check: assert min_effective_lines <= max_effective_lines before construction.
- Update both bounds together when tuning chunk sizes.
- Derive one from the other, e.g. max = min * 6, to keep the invariant.
Example fix
// before PythonCodeSplitter(min_effective_lines=20, max_effective_lines=10) // after PythonCodeSplitter(min_effective_lines=5, max_effective_lines=30)
Defensive patterns
Strategy: validation
Validate before calling
if min_effective_lines > max_effective_lines:
min_effective_lines, max_effective_lines = max_effective_lines, min_effective_lines Type guard
def is_ordered_range(min_l, max_l) -> bool:
return isinstance(min_l, int) and isinstance(max_l, int) and 1 <= min_l <= max_l Try / catch
try:
splitter = PythonCodeSplitter(min_effective_lines=min_l, max_effective_lines=max_l)
except ValueError as e:
raise ConfigError(f"Invalid line range: {e}") from e Prevention
- Use keyword arguments to avoid swapping positional parameters.
- Change min and max together when tuning.
- Assert the invariant in config tests: min <= max.
When it happens
Trigger: Calling PythonCodeSplitter(min_effective_lines=20, max_effective_lines=10), or building both from config where the values were swapped or one was updated without the other.
Common situations: Swapped argument order in a positional call, config edits that raised min but not max, or programmatic shrinking of max below an existing min.
Related errors
- 'response_fn' must return an assistant ChatMessage, got '{re
- Cannot stream multiple responses, please set n=1.
- A `ChatMessage` must contain at least one `TextContent`, `To
- top_k must be greater than 0.
- top_k must not be negative.
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/5f3d15b1e3bd01a9.
Report an issue: GitHub.