Explore the Structured Outputs functionality within the Azure.AI.OpenAI NuGet package to implement custom logic in your .NET AI project.
In some scenarios, receiving a structured JSON response is essential for your Azure OpenAI project. To meet this requirement, OpenAI introduced Structured Outputs, a feature that ensures the Large Language Model (LLM) generates responses that adhere to a provided JSON schema. This way, you don’t have to worry about the model omitting required keys or producing invalid enum values.
In this blog post, we’ll create a simple .NET console application to demonstrate two use cases of Structured Outputs. In the first example, we’ll solve a mathematical problem step-by-step, with explanations and the current state of the problem at each step. In the second example, we’ll generate a list of country information.
To test our application, you’ll need either a valid OpenAI API key or access to an active Azure OpenAI Service.
The first screenshot demonstrates the host selection process.
Based on your selection, you will be prompted to enter the necessary parameters.
Finally, the user selects between solving a math problem or retrieving country information.
Let’s start with a math problem. Simply enter your equation, and the Large Language Model will solve it, providing a step-by-step explanation.
When selecting country information, the user enters a comma-separated list of countries and receives a list of countries with the specified properties.
If you are more interested into details, please see the following posts on medium.com or in my personal blog:





