class Riffer::Agent::StructuredOutput
Parses and validates structured JSON responses against a Riffer::Params schema.
Attributes
The schema parameters.
Public Class Methods
Source
# File lib/riffer/agent/structured_output.rb, line 14 def initialize(params) @params = params end
Public Instance Methods
Source
# File lib/riffer/agent/structured_output.rb, line 22 def json_schema(strict: false) @params.to_json_schema(strict: strict) end
Returns the JSON Schema for this structured output.
Source
# File lib/riffer/agent/structured_output.rb, line 30 def parse_and_validate(json_string) parsed = JSON.parse(json_string, symbolize_names: true) validated = @params.validate(parsed) Result.new(object: validated) rescue JSON::ParserError => e Result.new(error: "JSON parse error: #{e.message}") rescue Riffer::ValidationError => e Result.new(error: "Validation error: #{e.message}") end
Parses a JSON string and validates it against the schema, returning a Result carrying either the validated object or an error message.