AI & LLM

LLM Tool / Function Call JSON Example

A JSON example of LLM function calling — the tool definition you send and the tool_call the model returns with arguments. Copy-ready for OpenAI and Anthropic tool use.

{
  "id": "call_9aZ2kQ7rT1vBnM3p",
  "type": "function",
  "function": {
    "name": "get_weather",
    "arguments": "{\"location\":\"Ahmedabad, IN\",\"unit\":\"celsius\"}"
  }
}

Field Reference

idrequiredstringUnique id for this tool call; echo it back in the tool result message
typerequiredstringCall type — 'function' for function calling
function.namerequiredstringName of the tool the model chose to call; must match a defined tool
function.argumentsrequiredstring (JSON)Arguments as a JSON-encoded string — parse it before use; the model may hallucinate fields

Variants

Tool definition (sent to the model)The JSON Schema you register so the model knows the tool's parameters.
Tool definition (sent to the model)
{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Get the current weather for a city.",
    "parameters": {
      "type": "object",
      "properties": {
        "location": {
          "type": "string",
          "description": "City and country, e.g. 'Ahmedabad, IN'"
        },
        "unit": {
          "type": "string",
          "enum": [
            "celsius",
            "fahrenheit"
          ],
          "default": "celsius"
        }
      },
      "required": [
        "location"
      ]
    }
  }
}
Tool result (sent back to the model)After running the function, return its output referencing the call id.
Tool result (sent back to the model)
{
  "role": "tool",
  "tool_call_id": "call_9aZ2kQ7rT1vBnM3p",
  "content": "{\"temperature\":34,\"unit\":\"celsius\",\"conditions\":\"Sunny\"}"
}

Common Use Cases

  • Letting an LLM trigger real functions like database lookups or API calls
  • Building agents that decide which tool to call and with what arguments
  • Forcing structured output by defining a single tool the model must call
function callingtool usellmopenai toolsagentsjson schema

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

The model generates arguments as text, so APIs return them as a JSON-encoded string. Always JSON.parse() the arguments and validate them against your schema before executing — the model can omit required fields or invent values.

Define a single tool whose parameters describe your desired shape and set tool_choice to force that function. The model then must respond with a tool_call whose arguments match your schema, giving you reliable structured output.

They're the same concept with different shapes. OpenAI returns a tool_calls array on the message with function.name and a stringified function.arguments; Anthropic returns a tool_use content block with name and a parsed input object. The orchestration loop — call tool, return result, continue — is identical.

Related JSON Examples