Skip to content

Fix Encodable for Dataclass and Scalar in #548#571

Draft
datvo06 wants to merge 5 commits intoeb-remove-responsefrom
dn-fix-encodable-eb-remove-response
Draft

Fix Encodable for Dataclass and Scalar in #548#571
datvo06 wants to merge 5 commits intoeb-remove-responsefrom
dn-fix-encodable-eb-remove-response

Conversation

@datvo06
Copy link
Contributor

@datvo06 datvo06 commented Feb 16, 2026

This PR:

  1. Add encodable for scalar and dataclass so that we won't break the test for these classes.
  2. Update fixtures.
  3. Minor fix on tool call encoding to use tool signatures.

@datvo06 datvo06 changed the title Fix Encodable for Dataclass and Scalar in #568 Fix Encodable for Dataclass and Scalar in #548 Feb 16, 2026
@datvo06 datvo06 requested a review from eb8680 February 16, 2026 03:01
@datvo06 datvo06 marked this pull request as draft February 16, 2026 03:08
@datvo06
Copy link
Contributor Author

datvo06 commented Feb 16, 2026

I found some failure tests. Checking more before re-opening

@eb8680
Copy link
Contributor

eb8680 commented Feb 16, 2026

The problem is the traces being replayed, which use the old response_model wrapper and are now obsolete. They need to be regenerated under the changes in #548, after which this PR is unnecessary.

@datvo06
Copy link
Contributor Author

datvo06 commented Feb 16, 2026

The problem is the traces being replayed, which use the old response_model wrapper and are now obsolete. They need to be regenerated under the changes in #548, after which this PR is unnecessary.

Yes. Fixtures are part of it, but also these following cases now fail, which I think because of this comment #548 (comment) (we dropped the default response_model, but did not add encodables to handle dataclass or primitives):

@Template.define
def primes(first_digit: int) -> int:
    """Give a prime number with {first_digit} as the first digit. Do not use any tools."""
    raise NotHandled


with handler(provider):
    assert type(primes(6)) is int

Result:

APIConnectionError: litellm.APIConnectionError: APIConnectionError: OpenAIException - Unsupported response_format type - <class 'int'>

And this:

@dataclasses.dataclass
class KnockKnockJoke:
    whos_there: str
    punchline: str


@Template.define
def write_joke(theme: str) -> KnockKnockJoke:
    """Write a knock-knock joke on the theme of {theme}. Do not use any tools."""
    raise NotHandled


@Template.define
def rate_joke(joke: KnockKnockJoke) -> bool:
    """Decide if {joke} is funny or not. Do not use any tools."""
    raise NotHandled


def do_comedy():
    joke = write_joke("lizards")
    print("> You are onstage at a comedy club. You tell the following joke:")
    print(
        f"Knock knock.\nWho's there?\n{joke.whos_there}.\n{joke.whos_there} who?\n{joke.punchline}"
    )
    if rate_joke(joke):
        print("> The crowd laughs politely.")
    else:
        print("> The crowd stares in stony silence.")


with handler(provider):
    do_comedy()

Result:

APIConnectionError: litellm.APIConnectionError: APIConnectionError: OpenAIException - Unsupported response_format type - <class '__main__.KnockKnockJoke'>

@eb8680
Copy link
Contributor

eb8680 commented Feb 16, 2026

The solution is not to handle scalars or dataclasses or other types that can theoretically be coerced into Pydantic piecemeal, but to do the encoding generically in the base case of Encodable.

@datvo06
Copy link
Contributor Author

datvo06 commented Feb 16, 2026

The solution is not to handle scalars or dataclasses or other types that can theoretically be coerced into Pydantic piecemeal, but to do the encoding generically in the base case of Encodable.

I see, I think we can make encoding more generic is adding WrappedEncodable. I added the first pass but will think of what can be better.

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