Nous.ToolSchema (nous v0.15.5)

View Source

Convert tools to different schema formats for various providers.

Different LLM providers expect different tool schema formats:

  • OpenAI format: String keys, function wrapper
  • Anthropic format: Atom keys, input_schema field
  • Custom providers: May require format-specific adaptations

Examples

# Convert to OpenAI format (used by OpenAI, Groq, OpenRouter, local providers)
openai_schema = ToolSchema.to_openai(tool)
# Returns: %{"type" => "function", "function" => %{"name" => "...", ...}}

# Convert to Anthropic format (used by Claude)
anthropic_schema = ToolSchema.to_anthropic(tool)
# Returns: %{name: "...", description: "...", input_schema: %{type: :object, ...}}

The schema conversion preserves all tool metadata while adapting to provider requirements.

Summary

Functions

Convert tool to Anthropic tool schema (atom keys).

Convert tool to OpenAI function calling schema (string keys).

Functions

to_anthropic(tool)

@spec to_anthropic(Nous.Tool.t()) :: map()

Convert tool to Anthropic tool schema (atom keys).

Anthropic uses a different format with atom keys: %{ name: "tool_name", description: "Tool description", input_schema: %{

type: "object",
properties: %{...},
required: [...]

} }

to_openai(tool)

@spec to_openai(Nous.Tool.t()) :: map()

Convert tool to OpenAI function calling schema (string keys).