You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Workers AI now supports structured JSON outputs.
3
3
description: Workers AI JSON Mode adds structured outputs support
4
4
date: 2025-02-25T15:00:00Z
5
5
---
6
6
7
-
We've updated the Workers AI to support [JSON mode](/workers-ai/json-mode/), enabling applications to request a structured output response when interacting with AI models.
7
+
import { TypeScriptExample } from"~/components";
8
+
9
+
Workers AI now supports structured JSON outputs with [JSON mode](/workers-ai/json-mode/), which allows you to request a structured output response when interacting with AI models.
10
+
11
+
This makes it much easier to retrieve structured data from your AI models, and avoids the (error prone!) need to parse large unstructured text responses to extract your data.
12
+
13
+
JSON mode in Workers AI is compatible with the OpenAI SDK's [structured outputs](https://platform.openai.com/docs/guides/structured-outputs)`response_format` API, which can be used directly in a Worker:
Copy file name to clipboardExpand all lines: src/content/docs/workers/get-started/prompting.mdx
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1256,6 +1256,90 @@ function StateInterface() {
1256
1256
</configuration>
1257
1257
<key_points>
1258
1258
1259
+
- Imports the `Agent` class from the `agents-sdk` package
1260
+
- Extends the `Agent` class and implements the methods exposed by the `Agent`, including `onRequest` for HTTP requests, or `onConnect` and `onMessage` for WebSockets.
1261
+
- Uses the `this.schedule` scheduling API to schedule future tasks.
1262
+
- Uses the `this.setState` API within the Agent for syncing state, and uses type parameters to ensure the state is typed.
1263
+
- Uses the `this.sql` as a lower-level query API.
1264
+
- For frontend applications, uses the optional `useAgent` hook to connect to the Agent via WebSockets
1265
+
1266
+
</key_points>
1267
+
</example>
1268
+
1269
+
<example id="workers-ai-structured-outputs-json">
1270
+
<description>
1271
+
Workers AI supports structured JSON outputs with JSON mode, which supports the `response_format` API provided by the OpenAI SDK.
0 commit comments