Skip to content

Commit 5c6e63e

Browse files
authored
Merge pull request #5297 from MicrosoftDocs/main
5/30 11:00 AM IST Publish
2 parents 768223a + 2d53732 commit 5c6e63e

18 files changed

+62
-62
lines changed

articles/ai-foundry/model-inference/how-to/use-structured-outputs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: how-to
10-
ms.date: 4/29/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
ms.custom: references_regions

articles/ai-foundry/model-inference/includes/how-to-prerequisites-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
manager: nitinme
33
ms.service: azure-ai-model-inference
44
ms.topic: include
5-
ms.date: 1/21/2025
5+
ms.date: 05/29/2025
66
ms.author: fasantia
77
author: santiagxf
88
---

articles/ai-foundry/model-inference/includes/how-to-prerequisites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
manager: nitinme
33
ms.service: azure-ai-model-inference
44
ms.topic: include
5-
ms.date: 1/21/2025
5+
ms.date: 05/29/2025
66
ms.author: fasantia
77
author: santiagxf
88
---

articles/ai-foundry/model-inference/includes/use-structured-outputs/csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: include
10-
ms.date: 1/21/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
zone_pivot_groups: azure-ai-inference-samples

articles/ai-foundry/model-inference/includes/use-structured-outputs/intro.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
---
2-
manager: nitinme
2+
manager: scottpolly
33
ms.service: azure-ai-model-inference
44
ms.topic: include
5-
ms.date: 1/31/2025
6-
ms.author: fasantia
7-
author: santiagxf
5+
ms.date: 05/29/2025
6+
ms.reviewer: fasantia
7+
reviewer: santiagxf
8+
ms.author: mopeakande
9+
author: msakande
10+
ms.custom: include
811
---
912

1013
[!INCLUDE [Feature preview](~/reusable-content/ce-skilling/azure/includes/ai-studio/includes/feature-preview.md)]
1114

12-
When working with software, it's more challenging to parse free-form text outputs coming from language models. Structured outputs, like JSON, provide a clear format that software routines can read and process. This article explains how to use structured outputs to generate specific JSON schemas with the chat completions API with models deployed in Azure AI Foundry Models.
15+
Free-form outputs of language models can be difficult to parse by software applications. Structured outputs, like JSON, provide a clear format that software applications can read and process. This article explains how to use structured outputs to generate specific JSON schemas with the chat completions API for models deployed in Azure AI Foundry Models.
1316

14-
Typical scenarios of structured outputs include:
17+
The following list describes typical scenarios where structured outputs are useful:
1518

16-
> [!div class="checklist"]
17-
> * You need to extract specific information from a prompt and such information can be described as an schema with specific keys and types.
18-
> * You need to parse information contained in the prompts.
19-
> * You are using the model to control a workflow in your application where you can benefit from more rigid structures.
20-
> * You are using the model as a zero-shot or few-shot learner.
19+
* You need to extract specific information from a prompt and such information can be described as a schema with specific keys and types.
20+
* You need to parse information contained in the prompts.
21+
* You're using the model to control a workflow in your application where you can benefit from more rigid structures.
22+
* You're using the model as a zero-shot or few-shot learner.
2123

2224
## Prerequisites
2325

2426
To use structured outputs with chat completions models in your application, you need:
2527

2628
[!INCLUDE [how-to-prerequisites](../how-to-prerequisites.md)]
2729

28-
* A chat completions model deployment with JSON and structured outputs support. If you don't have one read [Add and configure Foundry Models](../../how-to/create-model-deployments.md).
30+
* A chat completions model deployment with JSON and structured outputs support. If you don't have one, read [Add and configure Foundry Models](../../how-to/create-model-deployments.md).
2931

3032
* You can check which models support structured outputs by checking the column **Response format** in the [Models](../../concepts/models.md) article.
3133

articles/ai-foundry/model-inference/includes/use-structured-outputs/java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: include
10-
ms.date: 1/21/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
zone_pivot_groups: azure-ai-inference-samples

articles/ai-foundry/model-inference/includes/use-structured-outputs/javascript.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: include
10-
ms.date: 1/21/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
zone_pivot_groups: azure-ai-inference-samples
@@ -28,11 +28,11 @@ zone_pivot_groups: azure-ai-inference-samples
2828

2929
## How to use structured outputs
3030

31-
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
31+
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object, including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
3232

3333
### Example
3434

35-
To exemplify the scenario, let's try to parse the attributes of a GitHub Issue from its description.
35+
To illustrate, let's try to parse the attributes of a GitHub Issue from its description.
3636
3737
```javascript
3838
const url = 'https://api.github.com/repos/Azure-Samples/azure-search-openai-demo/issues/2231';
@@ -51,7 +51,7 @@ async function getIssueBody() {
5151
issueBody = await getIssueBody();
5252
```
5353

54-
The output of `issueBody` looks as follows:
54+
The output of `issueBody` is:
5555

5656
```output
5757
<!--
@@ -120,12 +120,11 @@ __github_issue_schema.json__
120120

121121
When defining schemas, follow these recommendations:
122122

123-
> [!div class="checklist"]
124-
> * Use clear and expressive keys.
125-
> * Use `_` if you need to separate words to convey meaning.
126-
> * Create clear titles and descriptions for important keys in your structure.
127-
> * Evaluate multiple structures until finding the one that works best for your use case.
128-
> * Take into account limitations when indicating schemas, which may vary per model.
123+
* Use clear and expressive keys.
124+
* Use `_` if you need to separate words to convey meaning.
125+
* Create clear titles and descriptions for important keys in your structure.
126+
* Evaluate multiple structures until you find the one that works best for your use case.
127+
* Take into account limitations when indicating schemas—limitations might vary per model.
129128

130129
Let's load this schema:
131130

@@ -136,9 +135,9 @@ const data = fs.readFileSync('./github_issue_schema.json', 'utf-8');
136135
const gitHubIssueSchema = JSON.parse(data);
137136
```
138137

139-
### Use structure outputs
138+
### Use structured outputs
140139

141-
We can use structure outputs with the defined schema as follows:
140+
We can use structured outputs with the defined schema as follows:
142141

143142

144143
```javascript
@@ -193,7 +192,7 @@ console.log(JSON.stringify(jsonResponseMessage, null, 4));
193192

194193
## Structured outputs in images
195194

196-
You can use structured outputs with multi-modal models to extract information from data like images.
195+
You can use structured outputs with multi-modal models to extract information from data such as image data.
197196

198197
Let's consider the following chart:
199198

articles/ai-foundry/model-inference/includes/use-structured-outputs/python.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: include
10-
ms.date: 1/21/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
zone_pivot_groups: azure-ai-inference-samples
@@ -35,11 +35,11 @@ zone_pivot_groups: azure-ai-inference-samples
3535

3636
## How to use structured outputs
3737

38-
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
38+
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object, including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
3939

4040
### Example
4141

42-
To exemplify the scenario, let's try to parse the attributes of a GitHub Issue from its description.
42+
To illustrate, let's try to parse the attributes of a GitHub Issue from its description.
4343

4444
```python
4545
import requests
@@ -49,7 +49,7 @@ response = requests.get(url)
4949
issue_body = response.json()["body"]
5050
```
5151

52-
The output of `issue_body` looks as follows:
52+
The output of `issue_body` is:
5353

5454
```output
5555
<!--
@@ -118,12 +118,12 @@ __github_issue_schema.json__
118118

119119
When defining schemas, follow these recommendations:
120120

121-
> [!div class="checklist"]
122-
> * Use clear and expressive keys.
123-
> * Use `_` if you need to separate words to convey meaning.
124-
> * Create clear titles and descriptions for important keys in your structure.
125-
> * Evaluate multiple structures until finding the one that works best for your use case.
126-
> * Take into account limitations when indicating schemas, which may vary per model.
121+
122+
* Use clear and expressive keys.
123+
* Use `_` if you need to separate words to convey meaning.
124+
* Create clear titles and descriptions for important keys in your structure.
125+
* Evaluate multiple structures until you find the one that works best for your use case.
126+
* Take into account limitations when indicating schemas—limitations might vary per model.
127127

128128
Let's load this schema:
129129

@@ -132,9 +132,9 @@ with open("github_issue_schema.json", "r") as f:
132132
github_issue_schema = json.load(f)
133133
```
134134

135-
### Use structure outputs
135+
### Use structured outputs
136136

137-
We can use structure outputs with the defined schema as follows:
137+
We can use structured outputs with the defined schema as follows:
138138

139139
```python
140140
response = client.complete(
@@ -197,17 +197,16 @@ class Issue(BaseModel, extra="forbid"):
197197

198198
Some things to notice:
199199

200-
> [!div class="checklist"]
201-
> * We represent schemas using a class that inherits from `BaseModel`.
202-
> * We set `extra="forbid"` to instruct Pyndantic to do not accept additional properties from what we have specified.
203-
> * We use type annotations to indicate the expected types.
204-
> * `Literal` indicates we expect specific fixed values.
200+
* We represent schemas using a class that inherits from `BaseModel`.
201+
* We set `extra="forbid"` to instruct Pydantic to _not_ accept additional properties from what we've specified.
202+
* We use type annotations to indicate the expected types.
203+
* `Literal` indicates we expect specific fixed values.
205204

206205
```python
207206
github_issue_schema = Issue.model_json_schema()
208207
```
209208

210-
### Use structure outputs
209+
### Use structured outputs
211210

212211
Let's see how we can use the schema in the same way:
213212

@@ -253,7 +252,7 @@ print(json.dumps(json_response_message, indent=4))
253252

254253
### Validate
255254

256-
Structured Outputs can still contain mistakes. If you see mistakes, try adjusting your instructions, providing examples in the system instructions, or splitting tasks into simpler subtasks.
255+
Structured outputs can still contain mistakes. If you see mistakes, try adjusting your instructions, providing examples in the system instructions, or splitting tasks into simpler subtasks.
257256

258257
It's a best practice to use validators to ensure you get valid structures. In Pydantic, you can verify the schema of a given object as follows:
259258

@@ -268,13 +267,13 @@ except ValidationError as e:
268267

269268
### Specifying a schema
270269

271-
There are some limitations that models may place in schemas definitions. Such limitations may vary per-model. **We recommend reviewing the documentation from the model provider** to verify that your schemas are valid.
270+
There are some limitations that models might place in schemas definitions. Such limitations might vary per-model. **We recommend reviewing the documentation from the model provider** to verify that your schemas are valid.
272271

273272
The following guidelines apply to most of the models:
274273

275274
#### Optional fields
276275

277-
Some models may require all the fields to be in the `required` section of the schema. If you need to use optional fields, use unions with null types to express that a given field can be optional.
276+
Some models might require all the fields to be in the `required` section of the schema. If you need to use optional fields, use unions with null types to express that a given field can be optional.
278277

279278
```python
280279
from pydantic import BaseModel
@@ -289,7 +288,7 @@ class Issue(BaseModel, extra="forbid"):
289288

290289
#### Nested types
291290

292-
Models may support indicating nesting types. You can compose complex structures as needed:
291+
Models might support indicating nesting types. You can compose complex structures as needed:
293292

294293
```python
295294
from pydantic import BaseModel
@@ -325,13 +324,13 @@ Verify the level of nesting supported by the model you're working with.
325324

326325
## Structured outputs in images
327326

328-
You can use structured outputs with multi-modal models to extract information from data like images.
327+
You can use structured outputs with multi-modal models to extract information from data such as image data.
329328

330329
Let's consider the following chart:
331330

332331
:::image type="content" source="../../media/use-structured-outputs/example-graph-treecover.png" alt-text="An example image showing a chart with the annual loss in thousand square kilometers of global tree cover across different climate zones." lightbox="../../media/use-structured-outputs/example-graph-treecover.png":::
333332

334-
We can define a generic schema that can be used to encode the information contained in the chart and then use it for further analysis. We use [Pyndatic objects](#use-pydantic-objects) as described before.
333+
We can define a generic schema that can be used to encode the information contained in the chart and then use it for further analysis. We use [Pydantic objects as described before](#use-pydantic-objects).
335334

336335
```python
337336
from pydantic import BaseModel

articles/ai-foundry/model-inference/includes/use-structured-outputs/rest.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: msakande
77
reviewer: santiagxf
88
ms.service: azure-ai-model-inference
99
ms.topic: include
10-
ms.date: 1/21/2025
10+
ms.date: 05/29/2025
1111
ms.author: mopeakande
1212
ms.reviewer: fasantia
1313
zone_pivot_groups: azure-ai-inference-samples
@@ -17,11 +17,11 @@ zone_pivot_groups: azure-ai-inference-samples
1717

1818
## How to use structured outputs
1919

20-
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
20+
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object, including expected values, types, and which ones are required. Those JSON objects are encoded as a string within the response of the model.
2121

2222
### Example
2323

24-
To exemplify the scenario, let's try to parse the attributes of a GitHub Issue from its description. The following [example is extracted from a GitHub issue in Azure-Samples repository](https://api.github.com/repos/Azure-Samples/azure-search-openai-demo/issues/2231).
24+
To illustrate, let's try to parse the attributes of a GitHub Issue from its description. The following [example is extracted from a GitHub issue in Azure-Samples repository](https://api.github.com/repos/Azure-Samples/azure-search-openai-demo/issues/2231).
2525

2626
```output
2727
<!--
@@ -88,9 +88,9 @@ __github_issue_schema.json__
8888
}
8989
```
9090

91-
### Use structure outputs
91+
### Use structured outputs
9292

93-
We can use structure outputs with the defined schema as follows:
93+
We can use structured outputs with the defined schema as follows:
9494

9595
__Request__
9696

@@ -186,7 +186,7 @@ __Response__
186186

187187
## Structured outputs in images
188188

189-
You can use structured outputs with multi-modal models to extract information from data like images.
189+
You can use structured outputs with multi-modal models to extract information from data such as image data.
190190

191191
Let's consider the following chart:
192192

@@ -275,9 +275,9 @@ __graph_schema.json__
275275
```
276276

277277

278-
## Use structure outputs
278+
## Use structured outputs
279279

280-
We can use structure outputs with the defined schema as follows:
280+
We can use structured outputs with the defined schema as follows:
281281

282282
__Request__
283283

-25.8 KB
Loading

0 commit comments

Comments
 (0)