{"record":{"id":"dcbe9d4a36754c7f","repo":"langchain-ai/langchain","slug":"x-should-be-0-and-number-of-columns","errorCode":null,"errorMessage":"x should be >= 0 and < number of columns","messagePattern":"x should be >= 0 and < number of columns","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"libs/core/langchain_core/runnables/graph_ascii.py","lineNumber":110,"sourceCode":"\n        Args:\n            x: x coordinate. Should be `>= 0` and `<` number of columns in\n                the canvas.\n            y: y coordinate. Should be `>= 0` an `<` number of lines in the\n                canvas.\n            char: character to place in the specified point on the\n                canvas.\n\n        Raises:\n            ValueError: if char is not a single character or if\n                coordinates are out of bounds.\n        \"\"\"\n        if len(char) != 1:\n            msg = \"char should be a single character\"\n            raise ValueError(msg)\n        if x >= self.cols or x < 0:\n            msg = \"x should be >= 0 and < number of columns\"\n            raise ValueError(msg)\n        if y >= self.lines or y < 0:\n            msg = \"y should be >= 0 and < number of lines\"\n            raise ValueError(msg)\n\n        self.canvas[y][x] = char\n\n    def line(self, x0: int, y0: int, x1: int, y1: int, char: str) -> None:\n        \"\"\"Create a line on ASCII canvas.\n\n        Args:\n            x0: x coordinate where the line should start.\n            y0: y coordinate where the line should start.\n            x1: x coordinate where the line should end.\n            y1: y coordinate where the line should end.\n            char: character to draw the line with.\n        \"\"\"\n        if x0 > x1:\n            x1, x0 = x0, x1","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/graph_ascii.py#L92-L128","documentation":"`AsciiCanvas.draw_on` bounds-checks the x coordinate: it must satisfy `0 <= x < cols`. An x at or beyond the canvas width, or negative, would index outside the grid, so `ValueError: x should be >= 0 and < number of columns` is raised (after the single-char check, before writing).","triggerScenarios":"Calling `draw_on(cols, y, \"#\")` (off-by-one at the right edge), a negative x from a line-drawing algorithm whose start point sits left of the canvas, or coordinates computed from node positions that overflow a canvas sized too small for the laid-out graph.","commonSituations":"Auto-sized canvases too narrow for wide graphs (node x-offsets exceed cols); porting/customizing `DrawGraph` layout math so boundary nodes land at x == cols; mirrored layouts producing negative x for leftmost labels.","solutions":["Size the canvas to the layout: ensure `cols > max_x` and `lines > max_y` used by draw calls.","Clamp coordinates: `x = min(max(x, 0), canvas.cols - 1)` when overflow is acceptable.","With the public API, prefer `print(runnable.get_graph().draw_ascii())`, which sizes the canvas internally, over manual coordinate math."],"exampleFix":"# before\ncanvas = AsciiCanvas(max_x, lines)  # max_x is a valid x -> out of bounds\n\ncanvas.draw_on(max_x, y, \"#\")\n\n# after\ncanvas = AsciiCanvas(max_x + 1, lines)\n\ncanvas.draw_on(max_x, y, \"#\")","handlingStrategy":"validation","validationCode":"assert 0 <= x < canvas.cols and 0 <= y < canvas.lines\ncanvas.draw_on(x, y, char)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size the canvas above the maximum drawn coordinate (cols > max_x).","Clamp coordinates when slight overflow is acceptable.","Prefer graph.draw_ascii() which sizes the canvas for you."],"tags":["graph","ascii-art","value-error","visualization","bounds-check","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}