Class: Phronomy::OutputParser::JsonParser
- Defined in:
- lib/phronomy/output_parser/json_parser.rb
Overview
Extracts and parses JSON from LLM response text.
Automatically handles Markdown code fences (json ...).
Instance Method Summary collapse
-
#parse(text) ⇒ Hash, Array
Result parsed with symbolize_names: true.
Methods inherited from Base
Methods included from Runnable
#batch, #invoke, #stream, #trace
Instance Method Details
#parse(text) ⇒ Hash, Array
Returns result parsed with symbolize_names: true.
13 14 15 16 17 18 |
# File 'lib/phronomy/output_parser/json_parser.rb', line 13 def parse(text) json_str = extract_json(text) JSON.parse(json_str, symbolize_names: true) rescue JSON::ParserError => e raise Phronomy::ParseError, "Failed to parse JSON: #{e.}\nInput: #{text}" end |