Skip to content

fix: preserve reasoning_effort parameter for GPT-5 models - #241

Closed
ishanrajsingh wants to merge 6 commits into
google:mainfrom
ishanrajsingh:fix-gpt5-reasoning-effort-parameter
Closed

ishanrajsingh wants to merge 6 commits into
google:mainfrom
ishanrajsingh:fix-gpt5-reasoning-effort-parameter

Conversation

@ishanrajsingh

@ishanrajsingh ishanrajsingh commented Sep 14, 2025 •

Copy link
Copy Markdown

Description

Fixes #237 - GPT-5-mini reasoning_effort Parameter Issue

Problem

When using reasoning_effort parameter with GPT-5 models, the following error occurred:

Exception: OpenAI API error: Completions.create() got an unexpected keyword argument 'reasoning'

This prevented users from utilizing GPT-5's reasoning capabilities through LangExtract, making the library incompatible with OpenAI's latest models.

Root Cause

The _normalize_reasoning_params() method in src/langextract/providers/openai.py incorrectly transformed the parameter from:

{"reasoning_effort": "minimal"} # ✅ Expected by OpenAI API

Into:

{"reasoning": {"effort": "minimal"}} # ❌ Invalid nested structure

This transformation caused OpenAI's API to reject the request with an "unexpected keyword argument" error.

Solution

  • Fixed parameter preservation: Modified _normalize_reasoning_params() to detect GPT-5 models and preserve reasoning_effort as a top-level parameter
  • Added model detection: Implemented case-insensitive detection for gpt-5, gpt-5-mini, gpt-5-nano variants
  • Enhanced parameter support: Added verbosity parameter support for GPT-5 models
  • Maintained backward compatibility: Non-GPT-5 models continue working with existing logic

Technical Changes

File: src/langextract/providers/openai.py

  • Updated _normalize_reasoning_params() method with GPT-5 model detection
  • Modified parameter handling in _process_single_prompt() to pass through reasoning_effort and verbosity
  • Updated infer() method to collect GPT-5-specific parameters

File: tests/test_gpt5_reasoning_fix.py (new)

  • Added comprehensive test coverage for parameter handling
  • Tests for GPT-5 model variants support
  • Backward compatibility verification
  • Mock API call validation

Impact

  • ✅ Fixes critical bug: GPT-5 models now work with reasoning parameters
  • ✅ Zero breaking changes: Existing code continues working unchanged
  • ✅ Enhanced functionality: Users can now access GPT-5's advanced reasoning features
  • ✅ Future-proof: Supports all current and future GPT-5 variants

How Has This Been Tested?

Unit Testing

`$ python -m pytest tests/test_gpt5_reasoning_fix.py -v
platform win32 -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
collected 4 items

tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt5_reasoning_effort_preserved PASSED [ 25%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt4_reasoning_effort_removed PASSED [ 50%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt5_variants_supported PASSED [ 75%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_api_call_with_reasoning_effort PASSED [100%]

========== 4 passed in 6.89s ==========`

Checklist

Integration Testing

Before Fix:

Exception: OpenAI API error: Completions.create() got an unexpected keyword argument 'reasoning'

After Fix:

$ python test_integration_fix.py LangExtract: model=gpt-5-mini [00:04]

✅ Fixed original issue google#237 - reasoning_effort now works correctly
✅ Unit tests: 4/4 passing
✅ Integration test: reaches API successfully (quota error proves fix works)
✅ Backward compatibility maintained

Fixes google#237
@github-actions github-actions Bot added the size/M Pull request with 150-600 lines changed label Sep 14, 2025
- Remove trailing whitespace throughout test files
- Fix import order (unittest.mock before third-party imports)
- Remove unused imports (pytest, Mock, json)
- Remove unused variables and broad exception catching
- Delete test_mock_verification.py (lint-problematic file)
- Maintain all test functionality while achieving lint compliance

All core functionality tested and working
@ishanrajsingh

Copy link
Copy Markdown
Author

@aksg87 I have worked on resolving the issue, you can check it out.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 2 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Oct 4, 2025

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Nov 7, 2025

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 4 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 8 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 10 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Jan 4, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

5 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

IgnatG added a commit to IgnatG/langextract that referenced this pull request Feb 17, 2026
Upstream PR google#241. Fixes reasoning_effort parameter being dropped for
GPT-5 models. Includes test coverage for the fix and linting cleanup.
IgnatG added a commit to IgnatG/langextract that referenced this pull request Feb 17, 2026
Applied PRs: google#356, google#369, google#329, google#267, google#305, google#326, google#352, google#359, google#317, google#362,
google#242, google#310, google#241. Moved from Low Priority to Applied section. Updated
cherry-pick log with all commit hashes.
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 3 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 4 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

3 similar comments
@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 4 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 4 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 4 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 10 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 11 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@aksg87

aksg87 commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

Hi @ishanrajsingh — thanks for working on this. The fix for #237 has landed in #429, which takes a simpler approach: passing reasoning_effort directly as a top-level Chat Completions parameter for all models rather than GPT-5 only. Closing this PR since the issue is resolved. Appreciate you flagging the bug!

@aksg87 aksg87 closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Pull request with 150-600 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gpt5-mini fails when reasoning_effort is passed via provider_kwargs

2 participants