---
description: Force Workers AI text generation models to return valid JSON output using response_format or JSON schemas.
title: JSON Mode
image: https://developers.cloudflare.com/og-docs.png
---

[Skip to content](#main-content)

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/workers-ai/llms.txt  
> Use this file to discover all available pages before exploring further.

# JSON Mode

Last updated Aug 25, 2026|Copy as Markdown|[View as Markdown](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/features/json-mode/index.md)|[Agent setup](https://66f4ea29.previews.developers.cloudflare.com/agent-setup/)

When we want text-generation AI models to interact with databases, services, and external systems programmatically, typically when using tool calling or building AI agents, we must have structured response formats rather than natural language.

Workers AI supports JSON Mode, enabling applications to request a structured output response when interacting with AI models.

## Schema

JSON Mode is compatible with OpenAI’s implementation; to enable add the `response_format` property to the request object using the following convention:

```json
{
  response_format: {
    title: "JSON Mode",
    type: "object",
    properties: {
      type: {
        type: "string",
        enum: ["json_object", "json_schema"],
      },
      json_schema: {},
    }
  }
}
```

Where `json_schema` must be a valid [JSON Schema ↗](https://json-schema.org/) declaration.

## JSON Mode example

When using JSON Format, pass the schema as in the example below as part of the request you send to the LLM.

```json
{
  "messages": [
    {
      "role": "system",
      "content": "Extract data about a country."
    },
    {
      "role": "user",
      "content": "Tell me about India."
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "capital": {
          "type": "string"
        },
        "languages": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "name",
        "capital",
        "languages"
      ]
    }
  }
}
```

The LLM will follow the schema, and return a response such as below:

```json
{
  "response": {
    "name": "India",
    "capital": "New Delhi",
    "languages": [
      "Hindi",
      "English",
      "Bengali",
      "Telugu",
      "Marathi",
      "Tamil",
      "Gujarati",
      "Urdu",
      "Kannada",
      "Odia",
      "Malayalam",
      "Punjabi",
      "Sanskrit"
    ]
  }
}
```

As you can see, the model is complying with the JSON schema definition in the request and responding with a validated JSON object.

## Supported Models

This is the list of models that now support JSON Mode:

* [@cf/meta/llama-3.1-8b-instruct-fast](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3.1-8b-instruct-fast/)
* [@cf/meta/llama-3.1-70b-instruct](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3.1-70b-instruct/)
* [@cf/meta/llama-3.3-70b-instruct-fp8-fast](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3.3-70b-instruct-fp8-fast/)
* [@cf/meta/llama-3-8b-instruct](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3-8b-instruct/)
* [@cf/meta/llama-3.1-8b-instruct](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3.1-8b-instruct/)
* [@cf/meta/llama-3.2-11b-vision-instruct](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/llama-3.2-11b-vision-instruct/)
* [@hf/nousresearch/hermes-2-pro-mistral-7b](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/hermes-2-pro-mistral-7b/)
* [@hf/thebloke/deepseek-coder-6.7b-instruct-awq](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/deepseek-coder-6.7b-instruct-awq/)
* [@cf/deepseek-ai/deepseek-r1-distill-qwen-32b](https://66f4ea29.previews.developers.cloudflare.com/workers-ai/models/deepseek-r1-distill-qwen-32b/)

We will continue extending this list to keep up with new, and requested models.

Note that Workers AI can't guarantee that the model responds according to the requested JSON Schema. Depending on the complexity of the task and adequacy of the JSON Schema, the model may not be able to satisfy the request in extreme situations. If that's the case, then an error `JSON Mode couldn't be met` is returned and must be handled.

JSON Mode currently doesn't support streaming.

Was this helpful?

YesNo

## On this page

[![](https://66f4ea29.previews.developers.cloudflare.com/_astro/logo.te5VL_aD.svg)Docs](https://66f4ea29.previews.developers.cloudflare.com/)

```json
{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/workers-ai/features/json-mode/#page","headline":"JSON Mode · Cloudflare Workers AI docs","description":"Force Workers AI text generation models to return valid JSON output using response\\_format or JSON schemas.","url":"https://developers.cloudflare.com/workers-ai/features/json-mode/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","dateModified":"2026-08-25","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["JSON"]}
```
