#953·monty

Support for BaseModel

Author: JonasKsCreated Sep 30, 2026Updated Sep 30, 2026
Labelsenhancement

We utilize Monty in ways it might not be initially intended for, such as allowing agents to write persistent functions that will be executed by other agents later.

This works really well, but I have two wishes for Monty scripts:

  • Input validation
  • Output validation

Example of an persistent function (written by an LLM):

python
limit = input.get("limit", 20)
if not isinstance(limit, int) or limit < 1 or limit > 100:
    raise ValueError("limit must be an integer between 1 and 100")
...

{"vendor_count": len(matches), "invoices": invoices}

What I'd prefer this to be:

python
class Input(BaseModel):
    limit: int = Field(default=20, ge=1, le=100)

class Invoice(BaseModel):
    amount: float

class Output(BaseModel):
    vendor_count: int
    invoices: list[Invoice]

args = Input.model_validate(input)
...

Output(vendor_count=len(matches), invoices=invoices)

If I had this, I would:

  • Require every persistent function to declare Input and Output as BaseModel subclasses, and refuse one that does not.
  • Wrap the body: validate input against Input before it runs, and the final expression against Output before it returns. A failure is a ValidationError naming the field.
  • Derive the two JSON Schemas from the models and store them. Other agents see them as the function's inputSchema and outputSchema when they list it as a tool.