Skip to content

feat(rlm): allow for passing pydantic models inside an RLM - #9306

Closed
isaacbmiller wants to merge 8 commits into
mainfrom
isaac/rlm-pydantic
Closed

isaacbmiller wants to merge 8 commits into
mainfrom
isaac/rlm-pydantic

Conversation

@isaacbmiller

@isaacbmiller isaacbmiller commented Feb 16, 2026 •

Copy link
Copy Markdown
Collaborator

RLM executes LLM-generated Python code in a sandboxed Deno/Pyodide interpreter. Host-side "tools" (Python functions) can be called from sandbox code, but arguments and return values cross a JSON serialization boundary. Previously, only simple types (str, int, float, bool) were handled — complex types like Pydantic models were silently ignored.

This PR adds first-class Pydantic model support across the full pipeline:

Tool parameters: dicts from the sandbox are coerced into Pydantic models before the tool is called, via pydantic.TypeAdapter python_interpreter.py:345-347
Tool returns: Pydantic model return values are serialized to JSON dicts before crossing back to the sandbox python_interpreter.py:349-350
Input variables: Pydantic model instances are serialized via model_dump(mode="json") for injection into sandbox code python_interpreter.py:475-476
Output fields: JSON schema metadata is attached to complex output types so the sandbox's SUBMIT() gets proper type hints rlm.py:327-337
Prompt metadata: REPLVariable now includes JSON schema for Pydantic inputs so the LLM understands their structure repl_types.py:77-83

Additionally, tool calls are now kwargs-only (no positional args), variadic tool signatures are rejected, and tool bridge errors in runner.js are returned as structured payloads instead of thrown exceptions (preventing Deno crashes from unhandled rejections).

…references. Introduce error handling for unresolved forward references and improve tool registration with TypeAdapters for parameter validation. Update tests to cover Pydantic model integration and error scenarios.
… serialize Pydantic models to JSON. Add tests to verify behavior for tools returning falsy values and Pydantic model outputs.
@okhat

okhat commented Feb 21, 2026

Copy link
Copy Markdown
Collaborator

Nice :D

…on, including improved handling of model types in tool parameters and outputs. Update JSON schema generation and add tests for model serialization and attribute access in the sandbox environment.
@isaacbmiller

Copy link
Copy Markdown
Collaborator Author

Closing in favor of smaller PRs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants