Skip to content

fix(llm): normalize JSON schema for OpenAI strict mode in chat_typed (#1656)#1670

Merged
bug-ops merged 2 commits intomainfrom
graph-extraction-openai-400
Mar 13, 2026
Merged

fix(llm): normalize JSON schema for OpenAI strict mode in chat_typed (#1656)#1670
bug-ops merged 2 commits intomainfrom
graph-extraction-openai-400

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 13, 2026

Summary

  • Adds inline_refs_openai() to resolve $ref/$defs before sending schema to OpenAI (OpenAI does not support JSON Schema $defs)
  • Adds normalize_for_openai_strict() to add additionalProperties: false and move all properties into required on every object schema node (including nested)
  • Applies both normalizers in chat_typed on OpenAiProvider before constructing the TypedChatRequest
  • anyOf: [{T}, {type: "null"}] patterns for Option<T> fields are preserved as-is (correct OpenAI strict mode representation for nullable fields)
  • 4 unit tests covering: basic additionalProperties/required, Option anyOf preservation, $ref inlining, nested object recursion

Test plan

  • cargo +nightly fmt --check passes
  • cargo clippy --workspace --features full -- -D warnings passes (0 warnings)
  • cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins passes (5264 tests)
  • Graph extraction tested end-to-end with OpenAI provider (gpt-4o-mini) — no longer returns 400 Bad Request

Closes #1656

…1656)

Add inline_refs_openai() to resolve $ref/$defs before sending to OpenAI,
and normalize_for_openai_strict() to add additionalProperties: false and
include all properties in required on every object schema. This fixes 400
Bad Request errors when using OpenAI providers for graph entity extraction.
@github-actions github-actions bot added bug Something isn't working documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines) labels Mar 13, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 13, 2026 18:48
@bug-ops bug-ops merged commit ca9fdb8 into main Mar 13, 2026
15 checks passed
@bug-ops bug-ops deleted the graph-extraction-openai-400 branch March 13, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(memory): graph extraction 400 Bad Request with OpenAI -- strict mode schema incompatibility

1 participant