Turn AI responses into a structured JSON output

Learn how to transform AI responses into a structured JSON output on Digibee, making your Agent’s results predictable and ready for deterministic integration flows.

This article extends the sentiment analysis API you assembled in the previous quickstart. You can now transform unstructured answers into structured outputs, ensuring your API always returns consistent, machine-readable results ready to be used in deterministic integration flows.

Prerequisites

Before continuing, make sure you have completed the Create your first AI Agent for sentiment analysis quickstart, including:

  • Selecting an LLM provider

  • Choosing a model

  • Configuring the account

Once the agent is properly configured, you can proceed to define a JSON Schema for the response.

Configuring a JSON Schema

A JSON Schema defines a predefined JSON structure with enforced fields and data types that the AI must follow in its response. See the configuration method below:

  1. In the Agent Component, click the gear icon (⚙️) next to the Model parameter.

  2. Enable Use JSON Schema.

  3. Add the following JSON Schema:

In the previous quickstart, the output format is flexible. By introducing a JSON Schema here, you ensure the response is always returned in a well-defined, structured format.

Testing the Agent

Use the following System and User Messages configured from the previous quickstart:

System message:

User message:

Before: Without JSON Schema

Without a JSON Schema, the Agent may return an unstructured response, for example:

The response format can change each time, which makes it difficult to process automatically.

After: With JSON Schema

With a JSON Schema configured, the Agent always returns a well-defined and predictable structure:

This ensures the output is always consistent and easy for other systems to read and use.

Result

Congratulations! You now have a sentiment analysis API that returns structured data in a consistent format, ideal for routing logic or storing in databases.

Last updated

Was this helpful?