Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Generation Fails with 'type' Error When Using Nested Pydantic Models #2403

Open
2 tasks
Fgulbahar opened this issue Jan 30, 2025 · 0 comments
Open
2 tasks

Comments

@Fgulbahar
Copy link

Fgulbahar commented Jan 30, 2025

Describe the bug

There's an error in the schema generation function (pydantic_model_to_json_schema) when handling Pydantic models. The error occurs in the clean_property function with the message: "Schema generation failed: Unexpected error in schema generation: 'type'". This happens when trying to create custom tool with nested models within the custom tool code sent - the system tries to generate JSON schemas for nested Pydantic models.

Please describe your setup

  • How did you install letta?
    • docker
  • Describe your setup
    • MacOS

Screenshots
Reproduction Steps
Here's a minimal example that reproduces the error:


from pydantic import BaseModel, Field

class DateFormatted(BaseModel):
    date: str = Field(..., description='The date string to be formatted')
    timezone: str = Field(..., description='The timezone to use for the date')
    date_format: str = Field(..., description='The format to apply to the date')

class WorkflowParams(BaseModel):
    date_formatted: DateFormatted = Field(
        ..., description='Format configuration for the date', title='DateFormatted'
    )
    valid: bool = Field(
        ..., description='If it is a valid value'
    )

When trying to generate the schema for these models, the error occurs in the clean_property function, suggesting that some property types aren't being handled correctly.

{ "detail": "Schema generation failed: Unexpected error in schema generation: 'type'" }

Additional context

The issue appears to be in the schema generation code where it doesn't properly handle all possible type structures that Pydantic can generate. The clean_property function needs to be more robust in handling:
Missing type fields
Complex type definitions
Nested model references

Letta Config
Using default configuration.

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

No branches or pull requests

1 participant