Class: LangExtract::Core::FormatHandler
- Inherits:
-
Object
- Object
- LangExtract::Core::FormatHandler
- Defined in:
- lib/langextract/core/format_handler.rb
Constant Summary collapse
- FENCE_PATTERN =
/```(?:json|yaml|yml)?\s*(.*?)```/im
Instance Method Summary collapse
Instance Method Details
#parse(output, format: :auto, strict: true, schema: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/langextract/core/format_handler.rb', line 13 def parse(output, format: :auto, strict: true, schema: nil) candidates = fenced_payloads(output) candidates << output.to_s if candidates.empty? parsed = parse_first(candidates, format) normalize_extractions(parsed).tap do |extractions| validate_schema!(extractions, schema) if schema end rescue FormatParsingError raise if strict [] end |