langchain-ai/langchain · warning · ValueError
char should be a single character
Error message
char should be a single character
What it means
`AsciiCanvas.draw_on` places one character at a coordinate, so `char` must be a string of length exactly 1. Passing a multi-character string (or empty string) has no single grid cell to occupy and raises `ValueError: char should be a single character`.
Source
Thrown at libs/core/langchain_core/runnables/graph_ascii.py:107
def point(self, x: int, y: int, char: str) -> None:
"""Create a point on ASCII canvas.
Args:
x: x coordinate. Should be `>= 0` and `<` number of columns in
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.View on GitHub (pinned to e32fa9a52e)
Solutions
- Draw multi-character content one character at a time: `for i, c in enumerate(s): canvas.draw_on(x + i, y, c)`.
- Use a single glyph (e.g. `">"`, `"*"`) where one cell is expected.
- Guard with `if len(char) != 1: raise/handle` before calling when char comes from user config.
Example fix
# before
canvas.draw_on(x, y, "->")
# after
for i, ch in enumerate("->"):
canvas.draw_on(x + i, y, ch) Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(char, str) and len(char) == 1 canvas.draw_on(x, y, char)
Type guard
from typing import TypeGuard
def is_single_char(s: object) -> TypeGuard[str]:
return isinstance(s, str) and len(s) == 1 Prevention
- Draw multi-char strings one character per cell.
- Use single glyphs for arrows/markers.
- Validate config-supplied glyphs before rendering.
When it happens
Trigger: Calling `canvas.draw_on(x, y, "->")`, `draw_on(x, y, "")`, or passing a label/arrow of length > 1; customizing `DrawGraph` (which itself draws arrow chars like `>` one cell at a time) with multi-char glyphs such as `"=>"` or emoji.
Common situations: Extending graph ASCII rendering with custom arrowheads or markers; drawing edge labels directly with `draw_on` instead of looping per character; passing a character variable that defaults to an empty string.
Related errors
- Canvas dimensions should be > 1
- x should be >= 0 and < number of columns
- Node with id {id} already exists
- Source node {source.id} not in graph
- Target node {target.id} not in graph
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/b1ac0a8d9eb9dc08.
Report an issue: GitHub.