Native Tool Calling
Introduction: From Prompted JSON to Native Tool Calls
You've just learned how to prompt the model to return structured JSON by including a schema in your system prompt. Now you're ready to take the next step: using OpenAI's native tool-calling feature, which provides stronger guarantees and implements Factor 4 (Tools are just structured outputs) of the 12-Factor Agents methodology directly. By the end of this lesson, you'll be able to define typed tool schemas, require their use via client.responses.create(...), and handle the structured output reliably in TypeScript.
Defining a Tool Schema
A tool schema is a formal definition of a function that the model can "call" by returning structured data. You define the function's name, what it does, and what parameters it expects. The schema follows JSON Schema conventions, which means you specify types, descriptions, and which fields are required.
The schema is a typed object that defines the interface between your code and the model. By importing the Tool type from the OpenAI SDK, TypeScript will catch any structural mistakes at compile time before your code ever runs. Each field plays a specific role:
type: For tool definitions, this is always set to"function".name: The identifier your code will use to recognize this tool — in this case,"final_answer".description: A natural language explanation that helps the model understand when it is appropriate to use this tool.strict: Setting this totrueenables Structured Outputs for tools, constraining successful tool-call arguments to match your parameter schema more reliably.parameters: An object usingJSON Schemanotation to define the expected arguments, such as our"answer"string.required: A list of property names that the model must include for the tool call to be considered valid.additionalProperties: false: A strict constraint that prevents the model from adding unexpected fields to the output.
This explicit contract gives you stronger provider-side constraints on the shape of successful final_answer calls. By defining these constraints, you reduce the amount of validation your application needs, but you do not eliminate defensive checks in your code.
