zylon-ai/private-gpt · error · ValueError
Chunk size must be greater than 0.
Error message
Chunk size must be greater than 0.
What it means
Raised by MarkdownHelper.sanitize_markdown when the effective chunk_size is below 1. Note the coercion just above: chunk_size = chunk_size or len(markdown), so None/0 fall back to the document length (safe for non-empty input); the only way to reach the error is passing a negative chunk_size explicitly. The value matters because the markdown is split into line batches of chunk_size for parallel sanitizing.
Source
Thrown at private_gpt/components/markdown/markdown_helper.py:160
index, lines = data
processed = []
for line in lines:
processed.append(MarkdownHelper._safe_sanity_data(line))
return index, processed
@staticmethod
def sanitize_markdown(
markdown: str, chunk_size: int | None = 256, max_workers: int | None = None
) -> str:
"""Sanitize markdown content to fix common formatting issues."""
if not markdown:
return markdown
chunk_size = chunk_size or len(markdown)
if chunk_size < 1:
raise ValueError("Chunk size must be greater than 0.")
max_workers = max_workers or 1
max_workers = min(max_workers, len(markdown) // chunk_size)
max_workers = max(1, max_workers)
# Split into chunks while trying to preserve line boundaries
lines = markdown.splitlines(keepends=True)
batches: list[list[str]] = list(iter_batch(lines, chunk_size))
# Create pool of workers
processed_chunks: list[tuple[int, list[str]]] = []
if max_workers == 1:
for index, batch in enumerate(batches):
_, processed = MarkdownHelper._sanity_markdown_batches((index, batch))
processed_chunks.append((index, processed))
else:
with ThreadPoolExecutor(max_workers=max_workers) as executor:
for index, batch in executor.map(View on GitHub (pinned to 4a030776a3)
Solutions
- Pass a positive chunk_size (typical 256) or None to let it default to the full document in one chunk.
- Clamp computed values: chunk_size = max(1, computed).
- Validate the chunk-size setting at load time (must be a positive int).
Example fix
# before out = MarkdownHelper.sanitize_markdown(md, chunk_size=len(md) // num_workers) # can be negative # after out = MarkdownHelper.sanitize_markdown(md, chunk_size=max(1, len(md) // num_workers))
Defensive patterns
Strategy: validation
Validate before calling
chunk_size = max(1, chunk_size) if chunk_size is not None else None MarkdownHelper.sanitize_markdown(md, chunk_size=chunk_size)
Type guard
def is_valid_chunk_size(n: Any) -> bool:
return n is None or (isinstance(n, int) and n >= 1) Try / catch
try:
out = MarkdownHelper.sanitize_markdown(md, chunk_size=cs)
except ValueError:
out = MarkdownHelper.sanitize_markdown(md) # default single chunk Prevention
- Clamp every computed chunk size with max(1, value).
- Validate chunk-size settings as positive ints in the config schema.
When it happens
Trigger: Calling sanitize_markdown(markdown, chunk_size=-5); computing chunk_size dynamically (e.g. len(text) // workers) and passing a negative result; configuration where a negative chunk size is read from settings/UI.
Common situations: Derived chunk sizes from division that can go negative; user-supplied settings validated only for presence, not sign; copy-paste of a size constant with the wrong sign.
Related errors
- Invalid system item in list (dict): {item}
- Invalid system item in list: {item}
- TOOL_NAME_CONFLICT
- zpgt.ingest.invalid_file_size.error
- INVALID_REQUEST_ERROR
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/5d5f14e022316d68.
Report an issue: GitHub.