Repository navigation
Description
Summary
When generated code fails inside PyodideSandbox, runner.js returns only the last non-empty line of the error message. For most exceptions that line is the useful one. For a pydantic ValidationError it is the docs URL, so the exception type, the failing field and the reason are all lost before the error reaches the caller.
Reproduction
prefab-ui 0.20.2 through FastMCP's GenerativeUI provider. The same code is on main (v0.21.1).
from prefab_ui.app import PrefabApp
from prefab_ui.components import Grid, Text
with PrefabApp() as app:
with Grid(columns={"default": 1, "lg": [2, 1]}): # breakpoint values must be int
Text("a")
Text("b")Actual error
Code execution failed: For further information visit https://errors.pydantic.dev/2.10/v/is_instance_of
Expected: the pydantic message itself, which names the model (Grid), the field (columns, lg) and the reason (a list where an int is expected), roughly:
Code execution failed: ValidationError: N validation errors for Grid
columns.dict[str,int].lg
Input should be a valid integer [type=int_type, input_value=[2, 1], input_type=list]
...
The same call with {"default": 1, "md": 2, "lg": 3} renders fine. The code is wrong; the problem is that the error doesn't say so.
Cause
src/prefab_ui/sandbox/runner.js, in the request loop's catch:
const msg = String(err.message || err);
const lines = msg.split("\n").filter((l) => l.trim());
const short = lines[lines.length - 1] || msg;
realLog(JSON.stringify({ id: requestId, error: short }));Pyodide's err.message is the full Python traceback, so the last line is normally ExcType: message. A pydantic ValidationError spans several lines and ends with For further information visit …. Keeping only the last line drops everything that names the problem.
Why it matters
The main caller of generate_ui is an LLM, and the error is the only thing it can correct from. With just the URL, the model has to guess which argument was wrong from the bare error code.
Possible fix
Either of these would work:
- In
runner.js: keep everything from the last line that starts an exception (/^[A-Za-z_][\w.]*(Error|Exception|Warning)\b/) to the end of the message, instead of only the last line, and cap the length. - In the Python harness: have
_execute_prefabcatch exceptions itself and return"".join(traceback.format_exception_only(exc)). For aValidationError, that is the full multi-line error without the traceback frames.
Activity
Mandy8639 commentedon Nov 29, 2026
Hi, I'd like to take this one.
My read matches the report:
runner.jskeeps only the last line of the error message, so a multi-line pydanticValidationError(which ends with the docs URL) loses the exception type, field, and reason.Plan: fix in
src/prefab_ui/sandbox/runner.js— keep everything from the last line that starts an exception (/^[A-Za-z_][\w.]*(Error|Exception|Warning)\b/) to the end of the message, capped in length, instead of only the last line. I'll first reproduce with the Grid example from the issue, then add tests covering the ValidationError case plus a normal single-line exception. Will open a PR once it's verified locally.