Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Nov 19, 2025

Title

fix: Support response_format parameter in completion → responses bridge

Relevant issues

Fixes #16810

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard
    requirement
    - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

Summary

When using completion() with models that have mode: "responses" (like o3-pro, gpt-5-codex), the response_format parameter with JSON schemas was being incorrectly handled, so :

  • Large schemas (>512 chars) fail with error: "Invalid 'metadata.schema_dict_json': string too long. Expected maximum 512, but got 1203"
  • Structured outputs are dropped
  • Users' code break

Details

The completionresponses bridge in litellm/completion_extras/litellm_responses_transformation/transformation.py was missing the conversion of:

  • response_format (Chat Completion API format)
  • text.format (Responses API format)

The inverse bridge (responsescompletion) already had this conversion implemented in commit 29f0ed2, but the completionresponses direction was incomplete.

Solution

Added _transform_response_format_to_text_format() method that converts:

  • response_format with json_schematext.format with json_schema
  • response_format with json_objecttext.format with json_object
  • response_format with texttext.format with text

Updated transform_request() to convert response_format parameter before sending to litellm.responses().

Files Changed

Modified:

  • litellm/completion_extras/litellm_responses_transformation/transformation.py
    • Added _transform_response_format_to_text_format() method (lines 592-647)
    • Modified transform_request() to handle response_format (lines 199-203)

Added:

  • tests/test_litellm/completion_extras/test_litellm_responses_transformation_transformation.py
    • 5 comprehensive tests covering all conversion scenarios

Testing ✅

  • JSON schema conversion
  • JSON object conversion
  • Text conversion
  • None/null handling
  • End-to-end transform_request() with response_format

Fixes BerriAI#16810

## Problem

When using completion() with models that have mode: "responses" (like o3-pro,
gpt-5-codex), the response_format parameter with JSON schemas was being ignored
or incorrectly handled, causing:
- Large schemas (>512 chars) to fail with "metadata.schema_dict_json: string too long" error
- Structured outputs to be silently dropped
- Users' code to break unexpectedly

## Root Cause

The completion -> responses bridge in
litellm/completion_extras/litellm_responses_transformation/transformation.py
was missing the conversion of response_format (Chat Completion format) to
text.format (Responses API format).

The inverse bridge (responses -> completion) already had this conversion
implemented in commit 29f0ed2, but the completion -> responses direction
was incomplete.

## Solution

Added _transform_response_format_to_text_format() method that converts:
- response_format with json_schema → text.format with json_schema
- response_format with json_object → text.format with json_object
- response_format with text → text.format with text

Updated transform_request() to detect and convert response_format parameter
before sending to litellm.responses().

## Changes

- Added _transform_response_format_to_text_format() method (lines 592-647)
- Modified transform_request() to handle response_format (lines 199-203)
- Added comprehensive tests to validate the conversion

## Testing

- 5 new unit tests covering all conversion scenarios
- Real API test with OpenAI confirming large schemas (>512 chars) work
- No more metadata.schema_dict_json errors

## Impact

Users can now use completion() with models that have mode: "responses" and:
- Use large JSON schemas without hitting metadata 512 char limit
- Get proper structured outputs
- Have their existing code continue working
@vercel
Copy link

vercel bot commented Nov 19, 2025

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug]: Sudden switch to responses from completions causing failures

1 participant