Skip to content

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

Merged
SharonHart merged 2 commits into
mainfrom
ronshaktuai/fix-langextract-params
Jul 13, 2026
Merged

fix(analyzer): honour language_model_params in BasicLangExtractRecogn…#2150
SharonHart merged 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
SharonHart
SharonHart previously approved these changes Jul 12, 2026

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.

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 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 13, 2026 05:43

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 3 out of 3 changed files in this pull request and generated 1 comment.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-analyzer)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-analyzer/presidio_analyzer
  analyzer_engine.py
  entity_recognizer.py
  presidio-analyzer/presidio_analyzer/input_validation
  schemas.py
  yaml_recognizer_models.py
  presidio-analyzer/presidio_analyzer/nlp_engine
  __init__.py
  nlp_engine_provider.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers
  __init__.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific
  __init__.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/australia
  au_abn_recognizer.py
  au_acn_recognizer.py
  au_medicare_recognizer.py
  au_tfn_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/germany
  de_bsnr_recognizer.py
  de_id_card_recognizer.py
  de_lanr_recognizer.py
  de_passport_recognizer.py
  de_social_security_recognizer.py
  de_tax_id_recognizer.py
  de_vat_id_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/india
  in_vehicle_registration_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/poland
  pl_pesel_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/generic
  phone_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/third_party
  basic_langextract_recognizer.py
  presidio-analyzer/presidio_analyzer/recognizer_registry
  recognizer_registry.py
  recognizers_loader_utils.py
Project Total  

The report is truncated to 25 files out of 70. To see the full report, please visit the workflow summary page.

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

@SharonHart SharonHart merged commit 08d5f18 into main Jul 13, 2026
86 of 89 checks passed
@SharonHart SharonHart deleted the ronshaktuai/fix-langextract-params branch July 13, 2026 06:59
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