Skip to content

Commit 6e36c37

Browse files
Fix: Enable suppress_parse_errors parameter in resolver_params (#261)
Added suppress_parse_errors to ALIGNMENT_PARAM_KEYS so it can be passed via resolver_params. Previously would throw TypeError. Based on brightertiger's original work in PR #252. Fixes #253 Co-authored-by: brightertiger <[email protected]>
1 parent 09757ce commit 6e36c37

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

langextract/extraction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def extract(
121121
reduce recall. Default is True. 'fuzzy_alignment_threshold' (float):
122122
Minimum token overlap ratio for fuzzy match (0.0-1.0). Default is 0.75.
123123
'accept_match_lesser' (bool): Whether to accept partial exact matches.
124-
Default is True.
124+
Default is True. 'suppress_parse_errors' (bool): Whether to suppress
125+
parsing errors and continue pipeline. Default is False.
125126
language_model_params: Additional parameters for the language model.
126127
debug: Whether to enable debug logging. When True, enables detailed logging
127128
of function calls, arguments, return values, and timing for the langextract

langextract/resolver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"enable_fuzzy_alignment",
4747
"fuzzy_alignment_threshold",
4848
"accept_match_lesser",
49+
"suppress_parse_errors",
4950
})
5051

5152

tests/init_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,51 @@ def test_extract_resolver_params_alignment_passthrough(
202202
self.assertEqual(kwargs.get("fuzzy_alignment_threshold"), 0.8)
203203
self.assertFalse(kwargs.get("accept_match_lesser"))
204204

205+
@mock.patch("langextract.annotation.Annotator.annotate_text")
206+
@mock.patch("langextract.extraction.factory.create_model")
207+
def test_extract_resolver_params_suppress_parse_errors(
208+
self, mock_create_model, mock_annotate
209+
):
210+
"""Test that suppress_parse_errors can be passed through resolver_params."""
211+
mock_model = mock.MagicMock()
212+
mock_model.requires_fence_output = False
213+
mock_model.schema = None
214+
mock_create_model.return_value = mock_model
215+
216+
mock_annotate.return_value = lx.data.AnnotatedDocument(
217+
text="test", extractions=[]
218+
)
219+
220+
mock_examples = [
221+
lx.data.ExampleData(
222+
text="Example text",
223+
extractions=[
224+
lx.data.Extraction(
225+
extraction_class="entity",
226+
extraction_text="example",
227+
),
228+
],
229+
)
230+
]
231+
232+
# This should not raise a TypeError about unknown key
233+
lx.extract(
234+
text_or_documents="test text",
235+
prompt_description="desc",
236+
examples=mock_examples,
237+
api_key="test_key",
238+
resolver_params={
239+
"suppress_parse_errors": True,
240+
"enable_fuzzy_alignment": False,
241+
},
242+
)
243+
244+
mock_annotate.assert_called()
245+
_, kwargs = mock_annotate.call_args
246+
self.assertIn("suppress_parse_errors", kwargs)
247+
self.assertTrue(kwargs.get("suppress_parse_errors"))
248+
self.assertFalse(kwargs.get("enable_fuzzy_alignment"))
249+
205250
@mock.patch("langextract.extraction.resolver.Resolver")
206251
@mock.patch("langextract.extraction.factory.create_model")
207252
def test_extract_resolver_params_none_handling(

0 commit comments

Comments
 (0)