Blog Post

Microsoft Developer Community Blog
4 MIN READ

GPT-5 FreeForm Tool Calling in TypeScript on Azure AI Foundry

Julia_Muiruri's avatar
Julia_Muiruri
Icon for Microsoft rankMicrosoft
Nov 19, 2025

Picture Carl, a Data Analyst, asked to prepare a comparison of mean petal length across Iris species. Instead of manually writing SQL and charting logic, he prompts an internal GPT-5 Agent: “Compute species-level means, then visualize petal length.” Behind the scenes, his Agentic workflow has two custom tools:

  • sql_exec_csvaccepts raw SQL and returns CSV results from an Iris dataset.
  • code_exec_javascriptexecutes raw JavaScript inside a hardened vm sandbox, parsing the CSV and rendering iris_plot.svg.

GPT-5 emits a SQL query (that's not wrapped in JSON), receives CSV output, generates JavaScript code that builds a chart, and finally summarizes the workflow—all in a handful of turns. This smooth, multi-tool flow is enabled by GPT-5’s FreeForm (custom) tool calling.

What Is FreeForm?

FreeForm (custom) tool calling allows GPT-5 to issue tool invocations whose payload is arbitrary unstructured raw text - SQL queries, Python scripts, JavaScript programs, Bash, config files, without being bound to JSON arguments conforming to a defined schema.

Traditional structured function calling solves reliable argument passing workloads but introduces friction for code-heavy and DSL-heavy workflows. You'd have to wrap code inside JSON strings, escape characters, then unpack and execute. With Freeform tool calling, you eliminate this round trip by registering a tool with { "type": "custom" } and GPT-5 can emit the exact text payload the tool expects - without the JSON envelope.

Why does this matter?

  • No schema friction: The model speaks in the tool's native language allowing you to run what it produces, rather than parsing JSON to recover string values.
  • Improved intermediate reasoning: Freeform output lets GPT-5 interleave natural-language commentary, raw code, and tool calls in a single response.
  • Multi-step chaining: Each tool output re-enters the conversation as plain text, and GPT-5 can reason on it directly.

 

Dimension
Structured Function Tools (JSON Schema)
FreeForm Custom Tools

Payload Shape

Example 
{
"name":"fn",
  "arguments":{...}
}

Raw text (code/query/script)

Validation

Automatic via schema (types, required)

Semantic validation implemented in executor

Parsing Overhead

JSON parsing + argument mapping

Minimal (string pass-through)

Ease of Tool Evolution

Schema changes would require code and prompt updates

Only need to update tool/ prompt descriptions

Readability in Logs (Observability)

Nested JSON obscures code

Natural language

Chaining Complexity

Each step returns JSON that must be parsed

Directly feed raw output back for the model to reason over

Errors

JSON malformed or missing required fields

Runtime execution errors

Application

  1. When strict argument validation is required. Schema enforces shape & type (Ex. Deterministic APIs)
  2. When downstream systems auto-ingest structured data
  1. When payload is primarily executable code. Skip JSON wrapping overhead especially when it adds no validation value

Tool discoverability

Model matches tool name, description and the expected schema

Model matches tool name and description

When Not to Use FreeForm

  • When strict validation is required (Ex. financial transaction parameters, coordinates, PII-handling flags).
  • For complex nested data (arrays of objects, deeply nested configs) where schema ensures shape.
  • For mass extraction tasks where consistent JSON accelerates downstream parsing.

Note: Depending on the scenario, you can implement a hybrid design to use structured tools for parameter selection and strict validation, then pass to custom (freeform) tools for code/ query execution.

Implementation breakdown - How Carl's Iris workflow is assembled

Pre-requisites

  1. Azure AI Foundry project
  2. GPT-5 model deployment - v1 API is required to access the latest model features

A link to the full sample code will be provided at the end of this blog, but here’s a minimal explanation of the core logic.

 

User prompt asking the model to produce SQL/ JavaScript as code blocks: -

  1. Write SQL to compute mean of sepal_length, sepal_width, petal_length, petal_width grouped by species. Return a tidy CSV with species and the four means (rounded to 2 decimals).
  2. Then write JavaScript to read that CSV string (provided as tool output), pretty-print a table, and produce a bar chart of mean petal_length by species.

 

Tool registry: Two custom tools are defined for the Responses API:

  • sql_exec_csv

Wraps an in-memory Iris dataset and returns CSV for SELECT queries, including a specialized path for group-by averages.

  • code_exec_javascript

Executes Node.js-compatible JavaScript inside a hardened vm context, capturing console output and rendering SVG charts via helper utilities.

Tools configuration of type custom - sql_exec_csv and code_exec_javascript

SQL Query generation and execution: First, the model generates the raw SQL query ...

GPT-5 generated raw SQL query following the prompt

... then it explicitly asks to call the sql_exec_csv tool, passing in the full SQL string as the payload.

In structured function calling, you’d expect to see JSON input like:

"arguments": "{\"query\":\"SELECT ...\"}" 

but in freeform tool calling, our custom tool isn't restricted to formatting the input in a JSON wrapper. Instead, it executes the raw SQL and returns a tidy CSV with the mean values rounded to 2 decimals, which is then wrapped in a function_call_output and inserted back into the conversation to feed into the context.

sql_exec_function executes the SQL from the model and returns CSV

JavaScript Code Execution: GPT-5 calls the code_exec_javascript tool to parse the CSV, pretty-print a table in the console, create and save the chart visual. The model provides full executable code as the tool argument there being no schema to tell it what fields to send. It simply writes the program

The JS code is executed using code_exec_javascript code

Our output is a mix of the requested result and commentary from the model

Output including a console table, commentary from GPT-5 and the location of the chart fileThe generated chart file

GPT-5 FreeForm tool calling elevates agentic development with less schema scaffolding, more expressive multi-step execution, and execute deterministically. Combined with Azure AI Foundry’s enterprise-grade governance stack, developers can prototype analytical workflows (like Carl's Iris example) and harden them for production quickly.

Resources

  1. Unlocking GPT-5’s Freeform Tool Calling: A New Era of Seamless Integration
  2. Free‑Form Function Calling - OpenAI Cookbook
  3. Python & TypeScript Code examples
Updated Nov 14, 2025
Version 1.0
No CommentsBe the first to comment