Problem/Motivation
Structured Output is something that has gone a little bit in the shadows due to Function Calling being added in 1.1.0, but its actually quite powerful as well and a very good fit with ECA.
I have added an issue here
📌
Document how to use structured output
Active
, because I realized its not even documented, but what you can do with providers that support it is, adding something in the line of
$schema = [
'name' => 'countries_population',
'schema' => [
'type' => 'object',
'properties' => [
'countries' => [
'type' => 'array',
'minItems' => 1,
'items' => [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string', 'minLength' => 1],
'iso_code' => ['type' => 'string', 'pattern' => '^[A-Z]{2,3}$'],
'population' => ['type' => 'integer', 'minimum' => 0],
'year' => ['type' => 'integer', 'minimum' => 1800, 'maximum' => 2100],
],
'required' => ['name', 'population'],
'additionalProperties' => false,
],
],
],
'required' => ['countries'],
'additionalProperties' => false,
],
];
$messages = [new ChatMessage("List the population of Germany, France and Spain")];
$input = new ChatInput("User", $messages);
$input->setChatStructuredJsonSchema($schema);
and it would return
{
"countries": [
{ "name": "France", "iso_code": "FR", "population": 68600000, "year": 2025 },
{ "name": "Germany", "iso_code": "DE", "population": 83600000, "year": 2025 },
{ "name": "Spain", "iso_code": "ES", "population": 49077984, "year": 2025 }
]
}
Because ECA has the "Render: unserialize" action, it should be able to split up the result and do really complex things with this.
Proposed resolution
Either add a new action specifically for structured output chat or add it as an option to the chat action.