zylon-ai/private-gpt · error · ValueError

view_range must contain exactly two integers

Error message

view_range must contain exactly two integers

What it means

ValueError in the view tool closure: when view_range is provided it must be a two-element [start_line, end_line]; the code checks len(view_range) != 2 before converting to a tuple for session.view. Any other length is rejected before any session round-trip.

Source

Thrown at private_gpt/components/tools/builders/text_editor_tool_builder.py:84

        if session is None:
            raise ValueError("code_execution provider is not configured.")
        return session

    async def build_view_tool(
        self,
        config: CodeExecutionSessionConfig,
        name: str = TEXT_EDITOR_VIEW_TOOL_NAME,
        type: str = TEXT_EDITOR_VIEW_TOOL_NAME + "_v1",
        description: str = TEXT_EDITOR_VIEW_TOOL_FN.metadata.description,
    ) -> ToolSpec:
        async def view(
            path: str,
            view_range: list[int] | None = None,
        ) -> list[ResultContentBlockType]:
            resolved_view_range: tuple[int, int] | None = None
            if view_range is not None:
                if len(view_range) != 2:
                    raise ValueError("view_range must contain exactly two integers")
                resolved_view_range = (view_range[0], view_range[1])

            session = await self._session(config)
            result = await session.view(
                path,
                view_range=resolved_view_range,
            )
            if not result.success:
                raise RuntimeError(result.error or "Unable to view file")
            output = _truncated(
                result.output, self._settings.code_execution.max_output_bytes
            )
            line_count = len(output.splitlines())
            start_line = resolved_view_range[0] if resolved_view_range else 1
            return [
                TextEditorCodeExecutionViewResultBlock(
                    content=output,
                    num_lines=line_count,

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Pass exactly two integers [start_line, end_line] (1-based, inclusive per the tool schema).
  2. For a single line, expand it: view_range=[n, n].
  3. Constrain the tool schema so view_range is an array of exactly 2 items.

Example fix

# before
await view(path="src/app.py", view_range=[42])

# after
await view(path="src/app.py", view_range=[42, 42])
Defensive patterns

Strategy: validation

Validate before calling

if view_range is not None:
    if not (isinstance(view_range, list) and len(view_range) == 2):
        raise ValueError("view_range must be [start_line, end_line]")
await view(path=path, view_range=view_range)

Type guard

def is_valid_view_range(vr) -> bool:
    return vr is None or (isinstance(vr, list) and len(vr) == 2 and all(isinstance(x, int) for x in vr))

Prevention

When it happens

Trigger: Calling the text editor view tool with view_range=[1], view_range=[], or view_range=[1, 10, 20]; only exactly two integers pass.

Common situations: LLM emits a single line number meaning 'show this line' instead of a range; client passes a slice object converted to a 3-arg list (start, stop, step); malformed JSON array from the agent.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/e1f6885c16e4037b. Report an issue: GitHub.