Skip to content

fix(analyzer): honour language_model_params in BasicLangExtractRecogn…#2150

Open
RonShakutai wants to merge 2 commits into
mainfrom
ronshaktuai/fix-langextract-params
Open

fix(analyzer): honour language_model_params in BasicLangExtractRecogn…#2150
RonShakutai wants to merge 2 commits into
mainfrom
ronshaktuai/fix-langextract-params

Conversation

@RonShakutai

Copy link
Copy Markdown
Contributor

Continues and completes PR #1943 started by @lsternlicht

Fixes #1942

Summary

BasicLangExtractRecognizer was silently dropping language_model_params
(like timeout, num_ctx) configured in YAML because langextract.extract()
ignores its language_model_params argument when a pre-built ModelConfig is
passed via config=. This fix merges language_model_params into provider_kwargs
so they reach the provider (e.g., Ollama) at runtime.

This PR builds on the original work from @lsternlicht and incorporates all
feedback from code review (Copilot, @RonShakutai), addressing edge cases and
adding comprehensive test coverage.

Changes

  • Merge language_model_params into provider_kwargs via setdefault()
    (explicit kwargs: entries still take precedence for backwards compatibility)
  • Guard against null YAML values with or {} safeguard
  • Strengthen regression tests to assert params reach ModelConfig.provider_kwargs
  • Add test case for kwargs: null edge case (per @RonShakutai feedback)
  • Update CHANGELOG

Validation

✅ All 22 tests pass
✅ Custom timeout reaches Ollama HTTP call
✅ num_ctx applied in langextract.extract()
✅ max_char_buffer passed correctly
✅ Edge case: kwargs: null in YAML doesn't crash

Addresses all feedback from PR #1943 (@lsternlicht, @copilot, @RonShakutai)

…izer

Fixes #1942. Merge language_model_params into provider_kwargs so timeout,
num_ctx and other LLM provider params configured in YAML actually reach
the provider (e.g. Ollama) instead of being silently dropped.

Also fixes TypeError when kwargs: or language_model_params: is null in YAML.

- Merge language_model_params into provider_kwargs via setdefault (so
  explicit kwargs: entries still win for backwards compatibility)
- Guard against null YAML values with 'or {}'
- Strengthen regression tests to assert params reach ModelConfig.provider_kwargs
- Add test for kwargs: null edge case
- Document fix in CHANGELOG

Related: #1943 (lsternlicht/fix-basic-langextract-language-model-params-dropped)
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report (presidio-anonymizer)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-anonymizer/presidio_anonymizer
  anonymizer_engine.py
  presidio-anonymizer/presidio_anonymizer/operators
  custom.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report (presidio-structured)

This PR does not seem to contain any modification to coverable code.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report (presidio-image-redactor)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-image-redactor/presidio_image_redactor
  dicom_image_pii_verify_engine.py
  document_intelligence_ocr.py
  image_analyzer_engine.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report (presidio-cli)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-cli/presidio_cli
  cli.py
Project Total  

This report was generated by python-coverage-comment-action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a configuration propagation bug in the analyzer’s BasicLangExtractRecognizer, ensuring that YAML-defined langextract.model.provider.language_model_params (e.g., timeout, num_ctx) actually reach the LangExtract provider when a pre-built ModelConfig is passed.

Changes:

  • Merge provider.language_model_params into ModelConfig.provider_kwargs using setdefault() so explicit provider.kwargs keeps precedence.
  • Harden YAML parsing for kwargs: null, extract_params: null, and language_model_params: null by treating them as empty dicts.
  • Add/strengthen regression tests to assert that parameters land on ModelConfig.provider_kwargs (not only on the language_model_params argument to langextract.extract()), plus an explicit kwargs: null edge-case test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
presidio-analyzer/presidio_analyzer/predefined_recognizers/third_party/basic_langextract_recognizer.py Ensures language_model_params are applied by merging into provider_kwargs used to build ModelConfig, and guards against null YAML values.
presidio-analyzer/tests/test_basic_langextract_recognizer.py Adds regression and backwards-compat tests verifying params reach ModelConfig.provider_kwargs, including a kwargs: null YAML edge case.
CHANGELOG.md Documents the analyzer fix and the null-YAML TypeError fix.

omri374
omri374 previously approved these changes Jul 9, 2026
… registry (#2153)

LM recognizers (BasicLangExtractRecognizer, AzureOpenAILangExtractRecognizer)
configured via a recognizer registry YAML silently ignored config_path: the
strict PredefinedRecognizerConfig schema has no config_path field and forbids
extras, so Pydantic dropped it and the recognizer fell back to its bundled
default model configuration.

Add a LangExtractRecognizerConfig model (extra=allow, explicit config_path
field) mirroring the existing HuggingFace/GLiNER configs, and register both
LM recognizer class names in CONFIG_MODEL_MAP so config_path (and other
recognizer-specific kwargs) survive validation and reach the constructor.

Adds regression tests covering config_path preservation via both the model
and the full ConfigurationValidator registry path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 12, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

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.

BasicLangExtractRecognizer silently drops provider.language_model_params (timeout, num_ctx, ...)

4 participants