langchain-ai/langchain · error · ValueError

y should be >= 0 and < number of lines

Error message

y should be >= 0 and < number of lines

What it means

Raised by AsciiCanvas.point() when the y coordinate is negative or >= the number of canvas lines. The ASCII canvas is a fixed-size 2D grid sized from the graph layout; any write outside it is rejected. In practice this is an internal guard hit while rendering a graph with draw_ascii(), usually because the computed layout produced a point outside the canvas bounds.

Source

Thrown at libs/core/langchain_core/runnables/graph_ascii.py:113

                the canvas.
            y: y coordinate. Should be `>= 0` an `<` number of lines in the
                canvas.
            char: character to place in the specified point on the
                canvas.

        Raises:
            ValueError: if char is not a single character or if
                coordinates are out of bounds.
        """
        if len(char) != 1:
            msg = "char should be a single character"
            raise ValueError(msg)
        if x >= self.cols or x < 0:
            msg = "x should be >= 0 and < number of columns"
            raise ValueError(msg)
        if y >= self.lines or y < 0:
            msg = "y should be >= 0 and < number of lines"
            raise ValueError(msg)

        self.canvas[y][x] = char

    def line(self, x0: int, y0: int, x1: int, y1: int, char: str) -> None:
        """Create a line on ASCII canvas.

        Args:
            x0: x coordinate where the line should start.
            y0: y coordinate where the line should start.
            x1: x coordinate where the line should end.
            y1: y coordinate where the line should end.
            char: character to draw the line with.
        """
        if x0 > x1:
            x1, x0 = x0, x1
            y1, y0 = y0, y1

        dx = x1 - x0

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. If calling point() directly, fix the y coordinate to satisfy 0 <= y < canvas.lines (check canvas.lines first)
  2. Shorten node names/labels so the computed layout fits the canvas
  3. Fall back to a different renderer, e.g. graph.draw_mermaid() or draw_mermaid_png(), which do not use the ASCII canvas
  4. If it reproduces on a plain graph with default settings, report it as a bug to langchain with a minimal reproducer

Example fix

// before
canvas.point(x, y, "*") // y from untrusted math
// after
if 0 <= y < canvas.lines and 0 <= x < canvas.cols:
    canvas.point(x, y, "*")
Defensive patterns

Strategy: try-catch

Validate before calling

// n/a: coordinates are computed internally by the layout; guard at the call level

Type guard

def in_bounds(canvas: AsciiCanvas, x: int, y: int) -> bool:
    return 0 <= x < canvas.cols and 0 <= y < canvas.lines

Try / catch

try:
    art = graph.draw_ascii()
except ValueError as e:
    art = graph.draw_mermaid()  # textual fallback

Prevention

When it happens

Trigger: Calling chain.get_graph().draw_ascii() (or graph_ascii.draw_ascii) on a graph whose sugiyama layout computes y coordinates that fall outside the canvas lines dimension; direct AsciiCanvas users calling point(x, y, char) with y >= canvas.lines or y < 0.

Common situations: Very wide or deeply nested graphs, graphs with long node labels, edge cases in grandalf layout rounding, or direct low-level canvas misuse. Most user code never touches AsciiCanvas directly, so hitting this means the layout step produced out-of-bounds geometry.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/d4960b619b3a7178. Report an issue: GitHub.