Skip to content

Union type support for structured outputs #559

@HaKIMus

Description

@HaKIMus

Unfortunately \Symfony\AI\Platform\Contract\JsonSchema\Factory::getTypeSchema doesn't support for \Symfony\Component\TypeInfo\Type\UnionType.

What I'm trying to achieve:

<?php

declare(strict_types=1);

namespace App\Agent\Application\StructuredOutput;

use Webmozart\Assert\Assert;

final class ChatStructuredOutput
{
    public function __construct(
        public string $title,
        public string $finalAnswer,
        /** @var array<int, ChartPart | TablePart | TextPart> */
        public array $parts = [],
    ) {
        Assert::allIsInstanceOf($this->parts, StructuredOutputPart::class);;
    }
}

It's quite possible I'm using the structured output wrong, and I should deal with the problem differently. I'm all ears how could I make it work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions