Skip to content

Make the AI extraction schema valid for strict structured outputs - #1540

Open
killecaptron wants to merge 1 commit into
Part-DB:masterfrom
killecaptron:ai-json-schema-strict-mode
Open

Make the AI extraction schema valid for strict structured outputs#1540
killecaptron wants to merge 1 commit into
Part-DB:masterfrom
killecaptron:ai-json-schema-strict-mode

Conversation

@killecaptron

Copy link
Copy Markdown
Contributor

The schema which the AI extractor sends along with its request is declared as a strict one ('strict' => true
in DTOJsonSchemaConverter), but it does not follow the two rules a schema has to follow to be accepted as
such: every object must forbid additional properties, and must list all of its properties as required. A
provider of the OpenAI family therefore refuses the request outright:

Invalid schema for response_format 'part_detail': In context=('properties', 'parameters', 'items'),
'additionalProperties' is required to be supplied and to be false.
("type":"invalid_request_error", "code":"invalid_json_schema", provider_name: Azure)

Which means the AI extractor cannot work with those models at all - "Create part from URL" fails every time.
Going through a gateway makes it harder to see: OpenRouter answers with its own "Provider returned error" and
keeps the reason in a field which is not part of the exception, so the failure looks like a misconfiguration on
the user's side. (I only got at the message above with #1539; the two are otherwise independent.)

Rather than sprinkling the two rules over a nested array literal, they are applied to the finished schema by
walking it. The schema stays as readable as it is now, and a property added later cannot forget them.

Requiring every property is only acceptable because the schema already expresses an optional value by allowing
null in its type, which the second test pins down alongside the rules themselves.

Verified on a real instance: with this change the extraction runs through against openai/gpt-5.6-luna via
OpenRouter, where it failed on every attempt before.

The schema which the AI extractor sends along with its request is
declared as a strict one, but does not follow the two rules a schema has
to follow to be accepted as such: every object must forbid additional
properties, and must list all of its properties as required. A provider
of the OpenAI family therefore refuses the request outright:

  Invalid schema for response_format 'part_detail': In context=
  ('properties', 'parameters', 'items'), 'additionalProperties' is
  required to be supplied and to be false.

Which means the AI extractor cannot work with those models at all. Going
through a gateway makes it harder to see: OpenRouter answers with its
own "Provider returned error" and keeps the reason in a field which is
not part of the exception, so the failure looks like a configuration
mistake on the user's side.

Rather than sprinkling the two rules over a nested array literal, they
are applied to the finished schema by walking it. The schema stays
readable, and a property added later cannot forget them.

Requiring every property is only acceptable because the schema already
expresses an optional value by allowing null in its type, which the
second test pins down alongside the rules themselves.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.66%. Comparing base (0f0ee60) to head (b2d6cf9).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1540      +/-   ##
============================================
+ Coverage     62.39%   62.66%   +0.26%     
- Complexity     9879     9885       +6     
============================================
  Files           736      736              
  Lines         31779    31789      +10     
============================================
+ Hits          19829    19919      +90     
+ Misses        11950    11870      -80     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant