Skip to content

fix(#309): Provider-specific JSON Schema for OpenAI/Gemini structured output - #310

Merged
mottych merged 1 commit into
devfrom
feature/issue-309-llm-schema-adapters
Apr 10, 2026
Merged

fix(#309): Provider-specific JSON Schema for OpenAI/Gemini structured output#310
mottych merged 1 commit into
devfrom
feature/issue-309-llm-schema-adapters

Conversation

@mottych

@mottych mottych commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes OpenAI 400 \invalid_json_schema\ for discriminated unions (e.g. \EmailInsightResponse.blocks): Pydantic emits \oneOf, which OpenAI strict structured outputs reject under \items.

Changes

  • New \llm_json_schema_adaptation.py: deep-copy and recursively rename \oneOf\ → \�nyOf, strip \discriminator.
  • \UnifiedAIEngine: after resolving the provider, adapt the prepared schema for \openai\ and \google_vertex; \�edrock\ unchanged.
  • \SingleShotExecutionContext.response_schema\ reflects the schema actually sent to the LLM.
  • Unit tests for \EmailInsightResponse\ and provider routing.

Testing

  • \pytest coaching/tests/unit/application/ai_engine/test_llm_json_schema_adaptation.py\ (Docker with coaching requirements)

Closes #309.

Made with Cursor

- Add llm_json_schema_adaptation: oneOf→anyOf, strip discriminator for OpenAI strict mode

- Apply same union normalization for Vertex Gemini response_schema

- Bedrock unchanged (passes through; ignores schema)

- Unit tests for EmailInsightResponse / provider routing

Made-with: Cursor
@mottych
mottych merged commit 19a74bd into dev Apr 10, 2026
2 checks passed
mottych added a commit that referenced this pull request Apr 10, 2026
coaching/pyproject.toml lacked [tool.ruff.lint.isort] known-first-party, so Ruff treated coaching.* as third-party and failed I001 (e.g. unified_ai_engine.py), breaking CI/CD and Deploy Dev after #310.

Add known-first-party matching repo root; apply ruff check --fix across coaching/ for consistent import blocks.

Made-with: Cursor
@mottych
mottych deleted the feature/issue-309-llm-schema-adapters branch April 15, 2026 17:56
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