4D Blog

Home Product 4D AIKit: Structured Outputs

4D AIKit: Structured Outputs

October 16, 2025

Product

When using AI in your application, you often need outputs that your code can parse, not just free-form text. Whether you’re generating data for a user interface, automating business logic, or orchestrating multi-step reasoning, predictable, machine-readable responses are essential.

That’s why 4D 21’s 4D AIKit introduces the new response_format attribute, letting you define the exact structure of the model’s output to ensure consistency, validation, and smooth integration into your app logic.

WHY STRUCTURED OUTPUTS MATTER

Structured outputs are useful every time you need to parse or interpret what an AI model produces.

For example:

  • Data generation: Automatically create structured content such as product records, CRM entries, or configuration data that your app can use immediately.
  • Reasoning & Planning: You can ask the model to propose next steps or workflow options that your app can display or execute automatically.
  • Multi-step agents (ReAct pattern): Combine reasoning and acting, where the AI follows specific formats to guide its next action.
  • Chain-of-thought control (visible part only): Capture the reasoning steps that you decide to expose to users for transparency or debugging.
  • Debugging / Monitoring AI reasoning: Enforce structure so that the AI’s internal logic can be logged and analyzed.

Here’s a simple example of how an AI model could return structured reasoning data you can instantly parse in 4D:

{
"thought": "The customer seems satisfied overall but mentioned slow delivery.",
"next_step": "offer_discount"
}

Use case: The AI summarizes the reasoning and suggests a next action that your code can apply automatically.

Structured Outputs with response_format

When interacting with an AI model, developers often need results in a specific format, whether plain text, JSON objects, or data validated against a schema. With the new response_format attribute, you can now instruct the model to return its response in the exact structure you require.

Here’s another case where structured output ensures consistent, validated data, a financial summary returned as strict JSON:

var $client:=cs.AIKit.OpenAI.new($openAIKey)
var $chatHelper:=$ai.chat.create("You are a financial data analyst.")

// Define the expected response format for the AI
var $response_format:={type: "json_schema"; json_schema: {}}
$response_format.json_schema.name:="sales_summary"
$response_format.json_schema.schema:={type: "object"; properties: {}}
$response_format.json_schema.schema.properties.total_revenue:={type: "number"}
$response_format.json_schema.schema.properties.gross_margin:={type: "number"}
$response_format.json_schema.schema.properties.top_products:={Type: "array"; items: {Type: "String"}}
$response_format.json_schema.schema.required:=["total_revenue"; "gross_margin"; "top_products"]
$response_format.json_schema.schema.additionalProperties:=False

// Attach the JSON Schema format to the chat helper
$chatHelper.parameters.response_format:=$jsonFormat

// Compose the message to send to the AI:
var $message:="Here are the sales figures for Q3:\n"
$message+="- Product A: $120,000 in sales, 40% margin\n"
$message+="- Product B: $85,000 in sales, 35% margin\n"
$message+="- Product C: $60,000 in sales, 50% margin\n"
$message+="Please calculate the total revenue, the overall gross margin, "
$message+="and list the top 2 products by revenue."

var $result:=$chatHelper.prompt($message)
//$result.choice.message.text:="{
//    "total_revenue": 265000,
//    "gross_margin": 0,406603773,
//    "top_products": ["Product A","Product B"]
//    ]
//}"

The AI responds with a validated JSON object, ready to use in your database or UI, no post-processing required.

MODEL SUPPORT LANDSCAPE

Support for structured outputs varies depending on the model you’re using:

  • OpenAI GPT-4o and GPT-4-Turbo natively support response_format.

  • Local or other cloud models (e.g., Claude, Gemini, or Ollama models) may support structured outputs differently, sometimes via strict function calling, sometimes via text-based schema enforcement.

And remember: response_format isn’t limited to JSON. Depending on the model, other formats such as plain text, XML, or domain-specific syntaxes may also be supported.

Conclusion

With the response_format in 4D AIKit, you can ensure that your AI outputs are exactly as you need them, consistent, reliable, and ready to plug straight into your UI, database, or any other system. This feature helps developers parse AI completions effortlessly and integrate intelligence deeply into their 4D applications. It transforms AI from a simple chat partner into a powerful, structured reasoning engine, enabling smarter, more dynamic features than users ever imagined.

Discuss

Tags 21, 4D AIKit, AI, AI Tool Calling, Artificial Intelligence, OpenAI

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy