Module: LLM::Schema::Renderer Private

Extended by:
Renderer
Included in:
Renderer
Defined in:
lib/llm/schema/renderer.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal renderer for prompt-friendly schema output.

Instance Method Summary collapse

Instance Method Details

#render(node, indent: 0, name: nil, root: false) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Render a schema node as a human-readable string.

Parameters:

  • node (LLM::Schema::Leaf)

    The schema node to render

  • indent (Integer) (defaults to: 0)

    The indentation level

  • name (String, Symbol, nil) (defaults to: nil)

    The property name for nested nodes

  • root (Boolean) (defaults to: false)

    Whether the node is the root schema object

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/llm/schema/renderer.rb', line 21

def render(node, indent: 0, name: nil, root: false)
  line = (" " * indent).to_s
  if name
    line << name.to_s
    line << "?" unless node.required?
    line << ": "
  end
  line << type_name(node)
   = (node, include_required: !root)
  line << " (#{.join(", ")})" unless .empty?
  line << " - #{node.description}" if node.respond_to?(:description) && node.description
  nested = nested_lines(node, indent: indent + 2)
  ([line] + nested).join("\n")
end