langchain-ai/langchain · error · ValueError
Box dimensions should be > 1
Error message
Box dimensions should be > 1
What it means
Raised by AsciiCanvas.box() when width or height is <= 1. Boxes (node frames) must span at least 2 columns and 2 lines so the border has an interior. The width/height come from the vertex view produced by the grandalf sugiyama layout, so a node whose computed w/h collapsed to 1 triggers this while drawing.
Source
Thrown at libs/core/langchain_core/runnables/graph_ascii.py:174
"""
for i, char in enumerate(text):
self.point(x + i, y, char)
def box(self, x0: int, y0: int, width: int, height: int) -> None:
"""Create a box on ASCII canvas.
Args:
x0: x coordinate of the box corner.
y0: y coordinate of the box corner.
width: box width.
height: box height.
Raises:
ValueError: if box dimensions are invalid.
"""
if width <= 1 or height <= 1:
msg = "Box dimensions should be > 1"
raise ValueError(msg)
width -= 1
height -= 1
for x in range(x0, x0 + width):
self.point(x, y0, "-")
self.point(x, y0 + height, "-")
for y in range(y0, y0 + height):
self.point(x0, y, "|")
self.point(x0 + width, y, "|")
self.point(x0, y0, "+")
self.point(x0 + width, y0, "+")
self.point(x0, y0 + height, "+")
self.point(x0 + width, y0 + height, "+")
View on GitHub (pinned to e32fa9a52e)
Solutions
- If calling box() directly, pass width >= 2 and height >= 2
- Shorten or simplify node names so the layout gives each node a non-degenerate size
- Fall back to graph.draw_mermaid() or draw_mermaid_png() instead of draw_ascii()
- Report as a langchain bug if a default graph triggers it
Example fix
// before canvas.box(x, y, 1, h) // after canvas.box(x, y, max(2, w), max(2, h))
Defensive patterns
Strategy: try-catch
Validate before calling
if width < 2 or height < 2:
raise ValueError("box needs width >= 2 and height >= 2") Type guard
def valid_box(w: int, h: int) -> bool:
return w > 1 and h > 1 Try / catch
try:
graph.draw_ascii()
except ValueError:
graph.draw_mermaid() Prevention
- Never call AsciiCanvas.box with width/height <= 1
- Treat draw_ascii failures as layout issues and fall back to Mermaid rendering
When it happens
Trigger: Calling draw_ascii() on a graph where a vertex view has w <= 1 or h <= 1 (degenerate layout); direct AsciiCanvas.box(x0, y0, width, height) calls with width or height <= 1.
Common situations: Custom node labels or graphs that make the layout engine compute degenerate box sizes; manual canvas usage. Rare for normal chains using draw_ascii().
Related errors
- y should be >= 0 and < number of lines
- Not enough points to draw an edge
- Invalid edge coordinates: start_x={start_x}, start_y={start_
- Install grandalf to draw graphs: `pip install grandalf`.
- Found duplicate subgraph '{subgraph}' -- this likely means t
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/447ee7e891d996a8.
Report an issue: GitHub.