Skip to content

[Bug] BAMLAdapter incorrectly declares complex nested types as recursive #8715

@BenMcH

Description

@BenMcH

What happened?

When trying to use the new BAMLAdapter with a slightly more complex schema, it fails prior to inference due to an error indicating that it cannot handle recursive pydantic models, despite the schema not being recursive. The trigger seems to be the second use of the same BaseModel within the same type.

Steps to reproduce

This example is a little bit contrived, but it's a minimal reproduction:

import dspy
from dspy.adapters.baml_adapter import BAMLAdapter
from pydantic import BaseModel

adapter = BAMLAdapter()
lm = dspy.LM("openai/gpt-4.1-mini")
dspy.configure(lm=lm, adapter=adapter)

class Attribute(BaseModel):
    value: str
    tags: list[str]

class Event(BaseModel):
    title: Attribute
    location: Attribute

predict = dspy.Predict("email -> output: Event")

predict(email="Let's meet at 2pm next Tuesday")

DSPy version

3.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions