Skip to content

fix: honor explicit temperature when config= or model= is passed to extract() - #530

Open
fsaudm wants to merge 1 commit into
google:mainfrom
fsaudm:fix-temperature-config-path
Open

fsaudm wants to merge 1 commit into
google:mainfrom
fsaudm:fix-temperature-config-path

Conversation

@fsaudm

@fsaudm fsaudm commented Aug 23, 2026 •

Copy link
Copy Markdown

Description

extract() accepts a top-level temperature argument documented as "Set to 0.0
for deterministic output", but the value is only merged into provider kwargs in
the model_id branch of extraction.py. When a caller passes a pre-built
config= (factory.ModelConfig) or model= (a language model instance), the
argument is silently ignored: the request carries no temperature parameter at
all (the OpenAI provider omits it when the value is None), so generation runs
at the server default temperature.

We found this with a batch-invariant vLLM deployment: raw API probes at
temperature 0 were byte-identical across runs, while extractions through
langextract differed run to run. A wire capture showed the request parameters
were {"model", "n", "response_format"} with no temperature despite
temperature=0.0 being passed.

This PR:

  • config= branch: merges an explicit temperature into the config via
    dataclasses.replace, so the caller's ModelConfig is never mutated. An
    explicit kwarg wins over a config-supplied value; with no explicit kwarg the
    config value is untouched.
  • model= branch: emits a UserWarning instead of silently ignoring the
    argument (a constructed model has no provider-agnostic temperature setter, and
    silently mutating caller-configured state seemed worse). This mirrors the
    existing use_schema_constraints warning in the same branch.
  • Updates the temperature, config, and model docstrings with the
    precedence rule.

Fixes #529

Choose one: Bug fix

How Has This Been Tested?

Added tests/extract_precedence_test.py with four tests covering the
precedence rules: explicit kwarg wins over a config-supplied value, a
config-supplied value survives when no kwarg is passed, the caller's
ModelConfig is not mutated, and the model= branch warns. Ran the new file
and the full suite:

$ pytest tests/extract_precedence_test.py -v
$ pytest tests

All pass. The original symptom was also re-verified end to end against our
batch-invariant vLLM deployment: with the patch, extractions at
temperature=0.0 are byte-identical across runs, matching the raw API probes.

Checklist:

  • I have read and acknowledged Google's Open Source
    Code of conduct.
  • I have read the
    Contributing
    page, and I either signed the Google
    Individual CLA
    or am covered by my company's
    Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked
    issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked
    issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed
    Google's Python Style Guide
    and ran pylint over the affected code.

@github-actions github-actions Bot added the size/S Pull request with 50-150 lines changed label Aug 23, 2026
@google-cla

google-cla Bot commented Aug 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

…xtract()

The top-level temperature argument was only merged into provider kwargs
in the model_id branch. With a pre-built ModelConfig or model instance it
was silently ignored, so requests carried no temperature parameter and
generation ran at the server default, breaking the documented 'set to
0.0 for deterministic output' contract.

- config= branch: merge an explicit temperature via dataclasses.replace,
  explicit kwarg wins over a config-supplied value, and the caller's
  ModelConfig is never mutated.
- model= branch: emit a UserWarning instead of silently ignoring the
  argument, matching the existing use_schema_constraints warning.
- Four cases added to ExtractParameterPrecedenceTest.

Fixes google#529
@fsaudm

fsaudm commented Aug 23, 2026

Copy link
Copy Markdown
Author

@googlebot I signed it!

@fsaudm
fsaudm force-pushed the fix-temperature-config-path branch from 62a7987 to 9b7896b Compare August 23, 2026 22:29
@github-actions

github-actions Bot commented Sep 7, 2026

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 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 7 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Pull request with 50-150 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract(temperature=...) is silently ignored when config= or model= is passed

1 participant