class RubyLLM::Browser::Extract

Schema-bounded structured extraction from one allowlisted page.

The extraction schema is **pinned by the host** when the tool is constructed, not chosen by the model. This is a deliberate, security-motivated departure from a model-supplied schema: an attacker-controlled page cannot widen what is read out, and a model cannot smuggle an oversized or unexpected shape past policy. The Gem still validates the pinned schema for depth, property count, byte size, known keys and known types, and bounds the extracted JSON.

The returned data is untrusted evidence with a source locator; an ‘ok` status does not verify that any extracted claim is true.

Attributes

schema[R]

Public Class Methods

new(context:, schema:) click to toggle source

@param context [Context] the host-supplied, trusted execution context @param schema [Hash, String, Class] the host-pinned extraction schema

Calls superclass method RubyLLM::Browser::Tool::new
# File lib/ruby_llm/browser/tools/extract.rb, line 37
def initialize(context:, schema:)
  super(context: context)
  @schema = pinned_schema!(schema)
end

Public Instance Methods

execute(url:, instruction: nil, max_bytes: nil) click to toggle source
# File lib/ruby_llm/browser/tools/extract.rb, line 42
def execute(url:, instruction: nil, max_bytes: nil)
  report("Extracting from an approved page")
  engine.extract(url: url, schema: schema, instruction: instruction, max_bytes: max_bytes).to_h
rescue Error => e
  failure(e)
rescue StandardError
  unexpected_failure
end