Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 0c28b2b

Browse files
committed
fix: serializer initiatlization for recursive structured output
1 parent c551b0e commit 0c28b2b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Chain/StructuredOutput/ChainProcessor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
use PhpLlm\LlmChain\Exception\InvalidArgumentException;
1212
use PhpLlm\LlmChain\Exception\MissingModelSupport;
1313
use PhpLlm\LlmChain\Model\Response\StructuredResponse;
14+
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
15+
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
1416
use Symfony\Component\Serializer\Encoder\JsonEncoder;
17+
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
1518
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1619
use Symfony\Component\Serializer\Serializer;
1720
use Symfony\Component\Serializer\SerializerInterface;
@@ -24,7 +27,11 @@ public function __construct(
2427
private readonly ResponseFormatFactoryInterface $responseFormatFactory = new ResponseFormatFactory(),
2528
private ?SerializerInterface $serializer = null,
2629
) {
27-
$this->serializer = $serializer ?? new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
30+
if (null === $this->serializer) {
31+
$propertyInfo = new PropertyInfoExtractor([], [new PhpDocExtractor()]);
32+
$normalizers = [new ObjectNormalizer(propertyTypeExtractor: $propertyInfo), new ArrayDenormalizer()];
33+
$this->serializer = $serializer ?? new Serializer($normalizers, [new JsonEncoder()]);
34+
}
2835
}
2936

3037
public function processInput(Input $input): void

0 commit comments

Comments
 (0)