# Function schema

You describe each tool with a name, a description and a JSON schema for its parameters.

AI developers · Part 03: Tool calling · Card 2 of 10 · Last updated 2026-10-13

## Analogy

An OpenAPI spec for one endpoint, written for a model instead of a frontend dev.

## Code example

`tools.ts`

```typescript
const tools = [{
  type: "function",
  function: {
    name: "getOrder",
    description: "Get an order's status by order ID",
    parameters: {
      type: "object",
      properties: { id: { type: "string" } },
      required: ["id"],
    },
  },
}];
```

## In an agent

The schema tells the agent exactly which arguments to produce, so your code receives predictable input.

## Practice

### Interview questions

**How does function / tool calling work?**

- Describe each tool with a name, a description and a JSON schema for its parameters.
- The model returns which tool to call and with what arguments. It never executes code itself.
- Your code validates the arguments, runs the function, and sends the result back as a tool message.
- The model then continues with the result in context.

## Questions people ask

### How do I describe a function for OpenAI tool calling?

Give each tool a type of function, a name, a description, and a parameters object written as JSON schema: the property names, their types and which ones are required. The model uses this to decide when to call the tool and to produce arguments in exactly the shape your code expects.

### Can I write tool schemas with Zod instead of raw JSON schema?

Yes. Libraries such as LangChain's tool helper, and Zod's own JSON schema export, turn a Zod object into the JSON schema the model needs. The bonus is that the same Zod schema can then validate the arguments the model sends back, so you describe and check the input in one place.

## Related concepts

- [The tool_calls reply](https://studyvisually.com/learn/tech/ai-developers/tool-calling/tool-calls-response)
- [Arguments are a string](https://studyvisually.com/learn/tech/ai-developers/tool-calling/tool-arguments-string)
- [The tool message](https://studyvisually.com/learn/tech/ai-developers/tool-calling/tool-message)
- [Calling the model again](https://studyvisually.com/learn/tech/ai-developers/tool-calling/second-call)

Web page: https://studyvisually.com/learn/tech/ai-developers/tool-calling/function-schema
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=function-schema
