Nous.ToolSchema (nous v0.16.4)
View SourceConvert 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 Gemini/Vertex functionDeclarations schema (string keys).
Convert tool to OpenAI function calling schema (string keys).
Functions
@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: [...]} }
@spec to_gemini(Nous.Tool.t()) :: map()
Convert tool to Gemini/Vertex functionDeclarations schema (string keys).
Vertex/Gemini's function declaration is shaped like OpenAI's inner function
object, minus the strict field which is OpenAI-specific.
Returns:
%{
"name" => "...",
"description" => "...",
"parameters" => %{...}
}
@spec to_openai(Nous.Tool.t()) :: map()
Convert tool to OpenAI function calling schema (string keys).
Deprecated alias — call Nous.Tool.to_openai_schema/1 directly. This
module's to_anthropic/1 and to_gemini/1 are the actively used
conversions; to_openai/1 is only kept for backward compatibility.