Skip to content

[Platform] StructuredOutput use Serializer to hydrate values but rely on ReflectionProperty for the schema #937

@VincentLanglet

Description

@VincentLanglet

Hi @chr-hertel @OskarStark

I just found a bug which is easy to reproduce with

framework:
    serializer:
        enabled: true
        enable_attributes: true
        name_converter: 'serializer.name_converter.camel_case_to_snake_case'

And an output class like

class Foo
{
    public function __construct(public string $fooBar) {}
}

When using

$content = $this->agent->call($messages, [
            'response_format' => Foo::class,
])->getContent();

The schema is generated using the ReflectionProperty

$reflection = new \ReflectionClass($className);
return $this->convertTypes($reflection->getProperties());
so considered the field as fooBar
But the data is hydrated with the serializer
: $this->serializer->deserialize($innerResult->getContent(), $this->outputType, 'json');

so the serializer name converter is used and it will expect a foo_bar key instead of fooBar.

Currently the workaround is to do

class Foo
{
    public function __construct(
       #[SerializedName('fooBar')]
       public string $fooBar
    ) {}
}

Any clue on how to fix this ? Maybe the PlatformSubscriber shouldn't rely on the default serialzer of Symfony ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingPlatformIssues & PRs about the AI Platform componentStatus: Needs Review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions