Skip to content

PyodideSandbox keeps only the last line of an error, so a ValidationError arrives as just the docs URL #560

Open

Description

@nowireless4u

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_prefab catch exceptions itself and return "".join(traceback.format_exception_only(exc)). For a ValidationError, that is the full multi-line error without the traceback frames.

Activity

  1. added
    bug
    good first issue
    renderer
    on Nov 16, 2026
  2. Mandy8639 commented on Nov 29, 2026

    @Mandy8639

    Hi, I'd like to take this one.

    My read matches the report: runner.js keeps only the last line of the error message, so a multi-line pydantic ValidationError (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuerenderer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions