Describe the overall issue and situation
Passing format_type through resolver_params makes lx.extract crash with AttributeError: 'str' object has no attribute 'value' before the model is ever called. It isn't just YAML. FormatType.JSON fails the same way, and so do the strings "yaml" and "json". The key is still supported until v2.0.0 (FormatHandler.from_resolver_params maps it and emits a DeprecationWarning), so older code that sets it breaks.
from_resolver_params unwraps the enum to its string (val = val.value) and passes strings through as is, so the handler holds "yaml" instead of FormatType.YAML. _add_fences then calls .value on that str. With fence_output=False the prompt doesn't crash, but the examples render as JSON even though YAML was asked for, and parsing the YAML answer raises the same error. suppress_parse_errors doesn't catch it. This goes back to #239 (v1.1.0).
Steps to reproduce the issue
On main (7129597), Python 3.13, PyYAML 6.0.3. The fake model returns a fixed YAML answer, so nothing goes over the network.
import langextract as lx
from langextract.core import base_model
from langextract.core import types
class FakeModel(base_model.BaseLanguageModel):
def infer(self, batch_prompts, **kwargs):
for _ in batch_prompts:
output = "```yaml\nextractions:\n- person: Alice\n```"
yield [types.ScoredOutput(score=1.0, output=output)]
examples = [
lx.data.ExampleData(
text="Bob met Carol.",
extractions=[lx.data.Extraction("person", "Bob")],
)
]
result = lx.extract(
"Alice went home.",
prompt_description="Extract people.",
examples=examples,
model=FakeModel(),
resolver_params={"format_type": lx.data.FormatType.YAML},
show_progress=False,
)
print([(e.extraction_class, e.extraction_text) for e in result.extractions])
Actual behavior
What I get:
File ".../langextract/core/format_handler.py", line 149, in format_extraction_example
return self._add_fences(formatted) if self.use_fences else formatted
File ".../langextract/core/format_handler.py", line 249, in _add_fences
fence_type = self.format_type.value
AttributeError: 'str' object has no attribute 'value'
Same traceback with FormatType.JSON and a JSON answer.
Expected behavior
[('person', 'Alice')], which is what I get when I pass format_type=lx.data.FormatType.YAML to lx.extract directly.
Any additional content
Converting the value to FormatType in from_resolver_params fixes it. I have that ready with tests if the approach works for you. In my version an unknown value like "xml" raises ValueError. from_kwargs maps anything that isn't "json" to YAML instead, so tell me if you'd rather match that.
A plain string at the top level, lx.extract(..., format_type="yaml"), crashes the same way. I left that out since that value is also passed to the provider when you use model_id.
Describe the overall issue and situation
Passing
format_typethroughresolver_paramsmakeslx.extractcrash withAttributeError: 'str' object has no attribute 'value'before the model is ever called. It isn't just YAML.FormatType.JSONfails the same way, and so do the strings"yaml"and"json". The key is still supported until v2.0.0 (FormatHandler.from_resolver_paramsmaps it and emits a DeprecationWarning), so older code that sets it breaks.from_resolver_paramsunwraps the enum to its string (val = val.value) and passes strings through as is, so the handler holds"yaml"instead ofFormatType.YAML._add_fencesthen calls.valueon that str. Withfence_output=Falsethe prompt doesn't crash, but the examples render as JSON even though YAML was asked for, and parsing the YAML answer raises the same error.suppress_parse_errorsdoesn't catch it. This goes back to #239 (v1.1.0).Steps to reproduce the issue
On main (7129597), Python 3.13, PyYAML 6.0.3. The fake model returns a fixed YAML answer, so nothing goes over the network.
Actual behavior
What I get:
Same traceback with
FormatType.JSONand a JSON answer.Expected behavior
[('person', 'Alice')], which is what I get when I passformat_type=lx.data.FormatType.YAMLtolx.extractdirectly.Any additional content
Converting the value to
FormatTypeinfrom_resolver_paramsfixes it. I have that ready with tests if the approach works for you. In my version an unknown value like"xml"raisesValueError.from_kwargsmaps anything that isn't"json"to YAML instead, so tell me if you'd rather match that.A plain string at the top level,
lx.extract(..., format_type="yaml"), crashes the same way. I left that out since that value is also passed to the provider when you usemodel_id.