---
title: Структурированные выходные данные
url: https://platform.claude.com/docs/ru/build-with-claude/structured-outputs
description: Получайте проверенные результаты в формате JSON из агентных рабочих процессов
featureMetadata:
  status: stable
  zdr:
    eligibility: qualified
    note: "Excludes [Covered Models](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#model-specific-data-retention-requirements). Ваши подсказки и выходные данные Claude не хранятся. Кэшируется только JSON-схема — до 24 часов с момента последнего использования. Это также относится к строгому использованию инструментов (`strict: true` для инструментов), которое использует тот же конвейер грамматик."
  supportedModels:
    - claude-fable-5-2
    - claude-mythos-5-2
    - claude-fable-5-1
    - claude-mythos-5-1
    - claude-fable-5
    - claude-mythos-5
    - claude-mythos-preview
    - claude-opus-5-5
    - claude-opus-5
    - claude-sonnet-5-5
    - claude-sonnet-5
    - claude-haiku-5-5
    - claude-haiku-4-5-20251001
    - claude-opus-4-8
    - claude-opus-4-7
    - claude-opus-4-6
    - claude-sonnet-4-6
    - claude-opus-4-5-20251101
    - claude-sonnet-4-5-20250929
  supportedPlatforms:
    Claude API: stable
    Amazon Bedrock: stable
    Amazon Bedrock (bedrock-runtime): stable
    Claude Platform on AWS: stable
    Claude Models on Google Cloud (Anthropic managed): stable
    Claude Models on Google Cloud (Google managed): stable
    Microsoft Foundry: stable
---

Структурированные выходные данные (structured outputs) ограничивают ответы Claude определённой схемой, гарантируя корректный, пригодный для разбора вывод для последующей обработки. Структурированные выходные данные предоставляют две взаимодополняющие функции:

* **Выходные данные JSON** (`output_config.format`): получайте ответ Claude в определённом формате JSON, например, чтобы извлекать данные из изображений или текста, создавать структурированные отчёты или форматировать ответы API. Эта страница посвящена выходным данным JSON.
* **Строгое использование инструментов** (`strict: true`): гарантируйте проверку по схеме для имён инструментов и входных данных. См. [Строгое использование инструментов](https://platform.claude.com/docs/ru/agents-and-tools/tool-use/strict-tool-use).

Вы можете использовать эти функции независимо или [вместе в одном запросе](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#using-both-features-together).

## Зачем использовать структурированные выходные данные

Без структурированных выходных данных Claude может генерировать некорректные ответы JSON или недопустимые входные данные инструментов, которые нарушают работу ваших приложений. Даже при тщательном составлении подсказок вы можете столкнуться с:

* Ошибками разбора из-за недопустимого синтаксиса JSON
* Отсутствием обязательных полей
* Несогласованными типами данных
* Нарушениями схемы, требующими обработки ошибок и повторных попыток

Структурированные выходные данные гарантируют ответы, соответствующие схеме, благодаря ограниченному декодированию (constrained decoding):

* **Всегда корректно:** никаких ошибок разбора JSON
* **Типобезопасно:** гарантированные типы полей и обязательные поля
* **Надёжно:** не нужны повторные попытки из-за нарушений схемы

## Как это работает

<Steps>
  <Step title="Определите схему">
    Опишите нужную структуру в виде JSON-схемы или в виде типа в вашем языке. Схема следует спецификации JSON Schema с некоторыми [ограничениями](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations).
  </Step>

  <Step title="Отправьте её в output_config.format">
    Запрос передаёт схему в `output_config.format` с `type: "json_schema"`. Вспомогательные функции SDK задают это за вас.
  </Step>

  <Step title="Прочитайте ответ">
    Claude возвращает корректный JSON, соответствующий вашей схеме, в текстовом блоке содержимого ответа. Вспомогательные функции SDK разбирают его в ваш тип.
  </Step>
</Steps>

## Использование

<Tabs>
  <Tab title="cURL">
    ```bash
    curl https://api.anthropic.com/v1/messages \
      -H "content-type: application/json" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2026-10-21" \
      -d '{
        "model": "claude-opus-5-5",
        "max_tokens": 1024,
        "messages": [
          {
            "role": "user",
            "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_schema",
            "schema": {
              "type": "object",
              "properties": {
                "name": {"type": "string"},
                "email": {"type": "string"},
                "plan_interest": {"type": "string"},
                "demo_requested": {"type": "boolean"}
              },
              "required": ["name", "email", "plan_interest", "demo_requested"],
              "additionalProperties": false
            }
          }
        }
      }'
    ```

    Claude возвращает JSON наподобие этого в текстовом блоке содержимого ответа:

    ```json Output
    {
      "name": "John Smith",
      "email": "john@example.com",
      "plan_interest": "Enterprise",
      "demo_requested": true
    }
    ```
  </Tab>

  <Tab title="CLI">
    ```bash
    ant messages create <<'YAML'
    model: claude-opus-5-5
    max_tokens: 1024
    messages:
      - role: user
        content: >-
          Extract the key information from this email: John Smith
          (john@example.com) is interested in our Enterprise plan and wants
          to schedule a demo for next Tuesday at 2pm.
    output_config:
      format:
        type: json_schema
        schema:
          type: object
          properties:
            name: {type: string}
            email: {type: string}
            plan_interest: {type: string}
            demo_requested: {type: boolean}
          required: [name, email, plan_interest, demo_requested]
          additionalProperties: false
    YAML
    ```

    Claude возвращает JSON наподобие этого в текстовом блоке содержимого ответа:

    ```json Output
    {
      "name": "John Smith",
      "email": "john@example.com",
      "plan_interest": "Enterprise",
      "demo_requested": true
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python
    from pydantic import BaseModel
    # ...


    class ContactInfo(BaseModel):
        name: str
        email: str
        plan_interest: str
        demo_requested: bool


    client = Anthropic()

    response = client.messages.parse(
        model="claude-opus-5-5",
        max_tokens=1024,
        messages=[
            {
                "role": "user",
                "content": (
                    "Extract the key information from this email: "
                    "John Smith (john@example.com) is interested in our Enterprise plan "
                    "and wants to schedule a demo for next Tuesday at 2pm."
                ),
            }
        ],
        output_format=ContactInfo,
    )

    print(response.parsed_output)
    ```

    Передайте модель [Pydantic](https://docs.pydantic.dev/) в `client.messages.parse()` (рекомендуемый метод) как `output_format`. SDK преобразует схему модели, отправляет её как `output_config.format`, проверяет ответ и возвращает разобранную модель в `parsed_output`.

    Предыдущий пример выводит:

    ```text Output wrap
    name='John Smith' email='john@example.com' plan_interest='Enterprise' demo_requested=True
    ```

    Если ключи поля известны, используйте вложенную модель Pydantic, а не `dict`. SDK отправляет поле `dict` как объект с пустым `properties`, поэтому Claude может вернуть для него только `{}`. Если ключи заранее неизвестны, см. [Объекты с произвольными ключами](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#objects-with-arbitrary-keys).
  </Tab>

  <Tab title="TypeScript">
    ```typescript
    import { z } from "zod";
    import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";

    const ContactInfoSchema = z.object({
      name: z.string(),
      email: z.string(),
      plan_interest: z.string(),
      demo_requested: z.boolean()
    });

    const client = new Anthropic();

    const response = await client.messages.parse({
      model: "claude-opus-5-5",
      max_tokens: 1024,
      messages: [
        {
          role: "user",
          content:
            "Extract the key information from this email: " +
            "John Smith (john@example.com) is interested in our Enterprise plan " +
            "and wants to schedule a demo for next Tuesday at 2pm."
        }
      ],
      output_config: { format: zodOutputFormat(ContactInfoSchema) }
    });

    // Автоматически разбирается и проверяется
    console.log(response.parsed_output);
    ```

    Оберните схему [Zod](https://zod.dev/) в `zodOutputFormat()` и передайте её в `client.messages.parse()` как `output_config.format`. `zodOutputFormat()` преобразует схему, а `parse()` проверяет ответ и возвращает разобранный результат в `parsed_output`, типизированный в соответствии со схемой.

    Предыдущий пример выводит:

    ```text Output wrap
    {
      name: 'John Smith',
      email: 'john@example.com',
      plan_interest: 'Enterprise',
      demo_requested: true
    }
    ```

    Если ключи поля известны, используйте `z.object()`, а не `z.record()`. SDK отправляет поле `z.record()` как объект с пустым `properties`, поэтому Claude может вернуть для него только `{}`. Если ключи заранее неизвестны, см. [Объекты с произвольными ключами](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#objects-with-arbitrary-keys).
  </Tab>

  <Tab title="C#">
    ```csharp
    using Anthropic;
    using Anthropic.Models.Messages;
    using Anthropic.Services;

    var client = new AnthropicClient();

    var response = await client.Messages.Create<ContactInfo>(new MessageCreateParams
    {
        Model = Model.ClaudeOpus5_5,
        MaxTokens = 1024,
        Messages = [
            new UserMessageParam
            {
                Content = "Extract the key information from this email: "
                    + "John Smith (john@example.com) is interested in our Enterprise plan "
                    + "and wants to schedule a demo for next Tuesday at 2pm."
            }
        ],
    });

    if (response.Content.Select(block => block.Parsed()).OfType<ContactInfo>().FirstOrDefault() is { } contact)
    {
        Console.WriteLine(contact);
    }

    public record ContactInfo
    {
        public string Name { get; set; } = "";
        public string Email { get; set; } = "";
        public string PlanInterest { get; set; } = "";
        public bool DemoRequested { get; set; }
    }
    ```

    Передайте обычный класс или record C# в обобщённую перегрузку `Create<T>()`. SDK выводит JSON-схему из типа, преобразует её и разбирает каждый текстовый блок обратно в этот тип.

    Предыдущий пример выводит:

    ```text Output wrap
    ContactInfo { Name = John Smith, Email = john@example.com, PlanInterest = Enterprise, DemoRequested = True }
    ```
  </Tab>

  <Tab title="Go">
    ```go
    type ContactInfo struct {
    	Name          string `json:"name"`
    	Email         string `json:"email"`
    	PlanInterest  string `json:"plan_interest"`
    	DemoRequested bool   `json:"demo_requested"`
    }

    func main() {
    	client := anthropic.NewClient()

    	var contact ContactInfo
    	_, err := client.Beta.Messages.New(context.Background(), anthropic.BetaMessageNewParams{
    		Model:     anthropic.ModelClaudeOpus5_5,
    		MaxTokens: 1024,
    		Messages: []anthropic.BetaMessageParam{
    			anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(
    				"Extract the key information from this email: " +
    					"John Smith (john@example.com) is interested in our Enterprise plan " +
    					"and wants to schedule a demo for next Tuesday at 2pm.",
    			)),
    		},
    		OutputConfig: anthropic.BetaOutputConfigParam{
    			Format: anthropic.BetaJSONOutputFormatParam{Schema: &contact},
    		},
    	})
    	if err != nil {
    		panic(err)
    	}

    	fmt.Printf("%#v\n", contact)
    }
    ```

    <Note>
      Передача структуры в качестве схемы в Go находится в стадии бета-тестирования, поэтому в этом примере используется `client.Beta.Messages.New`. Чтобы использовать стабильный `client.Messages.New`, передайте JSON-схему, как показано в разделе [Использование необработанной JSON-схемы](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#using-a-raw-json-schema).
    </Note>

    SDK генерирует и преобразует JSON-схему из структуры и десериализует ответ в неё.

    Предыдущий пример выводит:

    ```text Output wrap
    main.ContactInfo{Name:"John Smith", Email:"john@example.com", PlanInterest:"Enterprise", DemoRequested:true}
    ```
  </Tab>

  <Tab title="Java">
    ```java
    static class ContactInfo {
        public String name;
        public String email;
        public String plan_interest;
        public boolean demo_requested;
    }

    void main() throws Exception {
        AnthropicClient client = AnthropicOkHttpClient.fromEnv();

        StructuredMessageCreateParams<ContactInfo> params = MessageCreateParams.builder()
            .model(Model.CLAUDE_OPUS_5_5)
            .maxTokens(1024)
            .addUserMessage("Extract the key information from this email: "
                + "John Smith (john@example.com) is interested in our Enterprise plan "
                + "and wants to schedule a demo for next Tuesday at 2pm.")
            .outputConfig(ContactInfo.class)
            .build();

        StructuredMessage<ContactInfo> response = client.messages().create(params);
        ContactInfo contact = response.content().stream()
            .flatMap(block -> block.text().stream())
            .findFirst().orElseThrow().text();
        IO.println(new ObjectMapper().writeValueAsString(contact));
    }
    ```

    Когда вы передаёте класс Java в `outputConfig()`, SDK выводит из него JSON-схему и проверяет её. Затем построитель создаёт `StructuredMessageCreateParams<T>`. Вместо преобразования схемы локальная проверка SDK отклоняет [ограничения, не поддерживаемые API](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations). Прочитайте разобранный результат с помощью `response.content().stream().flatMap(block -> block.text().stream()).findFirst().orElseThrow().text()`.

    Предыдущий пример выводит:

    ```json Output
    {"name":"John Smith","email":"john@example.com","plan_interest":"Enterprise","demo_requested":true}
    ```

    <Note>
      Объявляйте классы схем как классы верхнего уровня или как `static` вложенные классы. Это требование исходит от библиотеки Jackson Databind (`com.fasterxml.jackson.databind`), которую SDK использует для десериализации ответов JSON в экземпляры ваших классов и которая не может создавать экземпляры нестатических внутренних классов.
    </Note>

    <Accordion title="Стирание обобщённых типов">
      Java сохраняет информацию об обобщённых типах для полей в метаданных класса, но в других областях применяется стирание обобщённых типов (generic type erasure). Хотя JSON-схему можно вывести из поля `BookList.books` с типом `List<Book>`, корректную JSON-схему нельзя вывести из локальной переменной того же типа.

      Если при преобразовании ответа JSON в экземпляр класса Java возникает ошибка, сообщение об ошибке включает ответ JSON для упрощения диагностики. Если ваш ответ JSON может содержать конфиденциальную информацию, избегайте его прямого журналирования или убедитесь, что удаляете все конфиденциальные сведения из сообщения об ошибке.
    </Accordion>

    <Accordion title="Локальная проверка схемы">
      Структурированные выходные данные поддерживают [подмножество языка JSON Schema](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations). SDK автоматически генерирует схемы из классов в соответствии с этим подмножеством. Метод `outputConfig(Class<T>)` выполняет проверку схемы, выведенной из указанного класса.

      Ключевые моменты:

      * **Локальная проверка:** SDK проверяет схему без отправки запроса.
      * **Удалённая проверка:** API также проверяет JSON-схему при получении запроса.
      * **Совместимость версий:** если версия SDK устарела, локальная проверка может отклонить схему, которую принимает удалённая проверка.
      * **Отключение локальной проверки:** передайте `JsonSchemaLocalValidation.NO`, если столкнётесь с проблемами совместимости:

      ```java
      import com.anthropic.core.JsonSchemaLocalValidation;
      // ...

      static class BookList {
          public List<String> books;
      }

      void main() {
          StructuredMessageCreateParams<BookList> createParams = MessageCreateParams.builder()
              .model(Model.CLAUDE_OPUS_5_5)
              .maxTokens(2048)
              .outputConfig(BookList.class, JsonSchemaLocalValidation.NO)
              .addUserMessage("List some famous late twentieth century novels.")
              .build();
      }
      ```
    </Accordion>

    <Accordion title="Потоковая передача">
      Структурированные выходные данные также работают с потоковой передачей (streaming). Поскольку ответы поступают в виде событий потока, необходимо накопить полный ответ перед десериализацией JSON.

      Используйте `MessageAccumulator` для сбора строк JSON из потока. После накопления вызовите `MessageAccumulator.message(Class<T>)`, чтобы преобразовать накопленное `Message` в `StructuredMessage`, которое автоматически десериализует JSON в ваш класс Java.
    </Accordion>

    <Accordion title="Свойства JSON-схемы">
      Когда SDK выводит JSON-схему из ваших классов Java, по умолчанию он включает все свойства, представленные `public` полями или `public` методами-геттерами, и исключает не-`public` поля и методы-геттеры.

      Вы можете управлять видимостью с помощью аннотаций:

      * `@JsonIgnore` исключает `public` поле или метод-геттер.
      * `@JsonProperty` включает не-`public` поле или метод-геттер.

      Если вы определяете `private` поля с `public` методами-геттерами, SDK выводит имя свойства из геттера (например, `private` поле `myValue` с `public` методом `getMyValue()` создаёт свойство `"myValue"`). Чтобы использовать нестандартное имя геттера, аннотируйте метод с помощью `@JsonProperty`.

      Каждый класс должен определять хотя бы одно свойство для JSON-схемы. Ошибка проверки возникает, если ни поля, ни методы-геттеры не могут создать свойства схемы, например, когда:

      * В классе нет полей или методов-геттеров
      * Все `public` члены аннотированы `@JsonIgnore`
      * Все не-`public` члены не имеют аннотаций `@JsonProperty`
      * Поле использует тип `Map`, который создаёт пустое поле `"properties"` (чтобы избежать этого, см. [Объекты с произвольными ключами](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#objects-with-arbitrary-keys))
    </Accordion>

    <Accordion title="Композиция и наследование">
      Ваши классы Java могут использовать композицию и наследование для совместного использования структуры при определении JSON-схем. Каждый шаблон по-разному влияет на структуру вывода.

      **Композиция** создаёт вложенный вывод JSON. Вывод схемы из класса `Composed`, который включает `A` и `B`:

      ```java
      static class A {
          public String a;
      }

      static class B {
          public String b;
      }

      static class Composed {
          public A composedA;
          public B composedB;
      }
      ```

      Вывод JSON имеет следующую вложенную структуру:

      ```json Output
      {
        "composedA": { "a": "hello" },
        "composedB": { "b": "world" }
      }
      ```

      **Наследование** создаёт плоский вывод JSON. Вывод схемы из класса `Derived`, который расширяет `Base`:

      ```java
      static class Base {
          public String a;
      }

      static class Derived extends Base {
          public String b;
      }
      ```

      Вывод JSON имеет следующую плоскую структуру:

      ```json Output
      {
        "a": "hello",
        "b": "world"
      }
      ```
    </Accordion>

    <Accordion title="Аннотации (Jackson и Swagger)">
      Вы можете использовать аннотации Jackson Databind, чтобы обогатить JSON-схему, выводимую из ваших классов Java:

      ```java
      import com.fasterxml.jackson.annotation.JsonClassDescription;
      import com.fasterxml.jackson.annotation.JsonIgnore;
      import com.fasterxml.jackson.annotation.JsonPropertyDescription;

      static class Person {

          @JsonPropertyDescription("The first name and surname of the person")
          public String name;

          public int birthYear;

          @JsonPropertyDescription("The year the person died, or 'present' if the person is living.")
          public String deathYear;
      }

      @JsonClassDescription("The details of one published book")
      static class Book {

          public String title;
          public Person author;

          @JsonPropertyDescription("The year in which the book was first published.")
          public int publicationYear;

          @JsonIgnore
          public String genre;
      }

      static class BookList {
          public List<Book> books;
      }
      ```

      Сводка аннотаций:

      * `@JsonClassDescription`: добавляет описание к классу
      * `@JsonPropertyDescription`: добавляет описание к полю или методу-геттеру
      * `@JsonIgnore`: исключает `public` поле или геттер из схемы
      * `@JsonProperty`: включает не-`public` поле или геттер в схему

      Если вы используете `@JsonProperty(required = false)`, SDK игнорирует значение `false`. Схемы, выведенные из классов, всегда помечают все свойства как обязательные.

      Вы также можете использовать аннотации Swagger Core (OpenAPI 3) `@Schema` и `@ArraySchema` для ограничений, зависящих от типа:

      ```java
      import io.swagger.v3.oas.annotations.media.ArraySchema;
      import io.swagger.v3.oas.annotations.media.Schema;

      static class Article {

          @ArraySchema(minItems = 1)
          public List<String> authors;

          public String title;

          @Schema(format = "date")
          public String publicationDate;

          public int pageCount;
      }
      ```

      Локальная проверка удостоверяется, что вы не использовали неподдерживаемые ключевые слова ограничений, но значения ограничений локально не проверяются. Например, неподдерживаемое значение `"format"` может пройти локальную проверку, но вызвать удалённую ошибку.

      Если вы используете аннотации Jackson и Swagger для задания одного и того же поля схемы, приоритет имеет аннотация Jackson.
    </Accordion>
  </Tab>

  <Tab title="PHP">
    ```php
    use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
    use Anthropic\Lib\Contracts\StructuredOutputModel;

    $client = new Client();

    class ContactInfo implements StructuredOutputModel
    {
        use StructuredOutputModelTrait;

        public string $name;
        public string $email;
        public string $plan_interest;
        public bool $demo_requested;
    }

    $message = $client->messages->create(
        maxTokens: 1024,
        messages: [
            [
                'role' => 'user',
                'content' => 'Extract the key information from this email: '
                    . 'John Smith (john@example.com) is interested in our Enterprise plan '
                    . 'and wants to schedule a demo for next Tuesday at 2pm.',
            ],
        ],
        model: 'claude-opus-5-5',
        outputConfig: ['format' => ContactInfo::class],
    );

    $contact = $message->parsedOutput();
    if ($contact instanceof ContactInfo) {
        var_dump($contact);
    }
    ```

    Определите класс, который реализует `StructuredOutputModel` и использует `StructuredOutputModelTrait`, и передайте его имя в `outputConfig: ['format' => MyClass::class]`. SDK выводит JSON-схему из типов свойств PHP 8 класса, преобразует её и возвращает типизированный экземпляр из `$message->parsedOutput()`.

    `parsedOutput()` возвращает экземпляр вашей модели в случае успеха или `null` (либо массив ошибок), если разбор не удался. Используйте `instanceof`, чтобы сузить тип перед обращением к полям.

    Предыдущий пример выводит:

    ```text Output wrap
    object(ContactInfo)#42 (4) {
      ["name"]=>
      string(10) "John Smith"
      ["email"]=>
      string(16) "john@example.com"
      ["plan_interest"]=>
      string(10) "Enterprise"
      ["demo_requested"]=>
      bool(true)
    }
    ```

    <Accordion title="Вывод типов">
      SDK сопоставляет нативные типы свойств PHP 8 с JSON Schema:

      | Тип PHP                                    | JSON Schema                     |
      | ------------------------------------------ | ------------------------------- |
      | `string`                                   | `"string"`                      |
      | `int`                                      | `"integer"`                     |
      | `float`                                    | `"number"`                      |
      | `bool`                                     | `"boolean"`                     |
      | `array`                                    | `"array"` (см. примечание ниже) |
      | `?type` (допускающий null)                 | Необязательное поле             |
      | Класс, реализующий `StructuredOutputModel` | Вложенный объект                |

      Для свойств `array` SDK добавляет схему `items` только тогда, когда тип элемента — вложенная `StructuredOutputModel`, объявленная с помощью `#[Constrained(itemClass: MyModel::class)]` или docblock `/** @var MyModel[] */`. Массивы скалярных значений (`string[]`, `int[]`) создают неограниченный `{"type":"array"}`.

      Все свойства, не допускающие null, становятся обязательными полями.
    </Accordion>

    <Accordion title="Ограничения с атрибутом #[Constrained]">
      Добавляйте ограничения с помощью атрибута `#[Constrained]`:

      ```php
      use Anthropic\Lib\Attributes\Constrained;
      use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
      use Anthropic\Lib\Contracts\StructuredOutputModel;

      class Address implements StructuredOutputModel { use StructuredOutputModelTrait; public string $street; }

      class Profile implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          #[Constrained(description: 'Age in years', minimum: 0, maximum: 150)]
          public int $age;

          #[Constrained(format: 'email')]
          public string $email;

          #[Constrained(itemClass: Address::class, minItems: 1)]
          public array $addresses;
      }
      ```

      **Ограничения, применяемые API** (отправляются в схеме): `description`, `format`, `const`, `itemClass`, `minItems` (только 0 или 1).

      **Ограничения, проверяемые SDK** (удаляются из передаваемой схемы, добавляются в описание и проверяются по ответу): `minimum`, `maximum`, `multipleOf`, `minLength`, `maxLength`.
    </Accordion>
  </Tab>

  <Tab title="Ruby">
    ```ruby
    client = Anthropic::Client.new

    class ContactInfo < Anthropic::BaseModel
      required :name, String
      required :email, String
      required :plan_interest, String
      required :demo_requested, Anthropic::Boolean
    end

    message = client.messages.create(
      model: Anthropic::Model::CLAUDE_OPUS_5_5,
      max_tokens: 1024,
      messages: [{
        role: "user",
        content: "Extract the key information from this email: " \
          "John Smith (john@example.com) is interested in our Enterprise plan " \
          "and wants to schedule a demo for next Tuesday at 2pm."
      }],
      output_config: { format: ContactInfo }
    )

    contact = message.parsed_output
    puts contact
    ```

    Определите класс, расширяющий `Anthropic::BaseModel`, и передайте его в `messages.create()` как `output_config: { format: Model }`. SDK выводит JSON-схему из класса, преобразует её и присваивает разобранный результат атрибуту `parsed_output` ответа в виде типизированного объекта Ruby.

    Предыдущий пример выводит:

    ```text Output wrap
    {name: "John Smith", email: "john@example.com", plan_interest: "Enterprise", demo_requested: true}
    ```

    <Accordion title="Расширенные возможности моделей">
      Ruby SDK поддерживает дополнительные возможности определения моделей для более богатых схем:

      * **Ключевое слово `doc:`:** добавляет описания к полям для более информативного вывода схемы
      * **`Anthropic::ArrayOf[T]`:** типизированные массивы. Передавайте ограничения уровня массива (`min_items:`, `max_items:`) как ключевые аргументы для `required`/`optional`, а не для самого `ArrayOf`
      * **`Anthropic::EnumOf[:a, :b]`:** поля перечислений с ограниченными значениями
      * **`Anthropic::UnionOf[T1, T2]`:** типы объединений, сопоставляемые с `anyOf`

      ```ruby
      class FamousNumber < Anthropic::BaseModel
        required :value, Float
        optional :reason, String, doc: "why is this number mathematically significant?"
      end

      class Output < Anthropic::BaseModel
        required :numbers, Anthropic::ArrayOf[FamousNumber], min_items: 3, max_items: 5
      end

      message = client.messages.create(
        model: Anthropic::Model::CLAUDE_OPUS_5_5,
        max_tokens: 1024,
        messages: [{ role: "user", content: "give me some famous numbers" }],
        output_config: { format: Output }
      )

      message.parsed_output
      # => #<Output numbers=[#<FamousNumber value=3.14159... reason="Число пи — это...">...]>
      ```
    </Accordion>
  </Tab>
</Tabs>

## Как работает преобразование в SDK

Большинство вспомогательных функций SDK преобразуют схемы, использующие неподдерживаемые возможности. Этапы преобразования:

1. **Удаление неподдерживаемых ограничений** (например, `minimum`, `maximum`, `minLength`, `maxLength`)
2. **Обновление описаний** путём добавления каждого неподдерживаемого ограничения в описание поля (например, `{minimum: 100}`)
3. **Добавление `additionalProperties: false`** ко всем объектам
4. **Фильтрация строковых форматов** только до поддерживаемого списка
5. **Проверка ответов** по вашей исходной схеме со всеми её ограничениями, если вспомогательная функция проверяет ответы

Claude получает упрощённую схему, но вспомогательная функция, проверяющая ответы, всё равно применяет каждое ограничение в вашем коде.

**Пример:** поле с `minimum: 100` становится обычным целым числом в отправляемой схеме, а SDK добавляет `{minimum: 100}` в описание поля. Вспомогательная функция, проверяющая ответы, всё равно проверяет ответ на соответствие `minimum: 100`.

## Использование необработанной JSON-схемы

Чтобы использовать JSON-схему из файла, спецификации OpenAPI или кода, который строит её во время выполнения, передайте её в `output_config.format`.

<Tabs>
  <Tab title="cURL">
    ```bash
    curl https://api.anthropic.com/v1/messages \
      -H "content-type: application/json" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2026-10-21" \
      -d '{
        "model": "claude-opus-5-5",
        "max_tokens": 1024,
        "messages": [
          {
            "role": "user",
            "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_schema",
            "schema": {
              "type": "object",
              "properties": {
                "name": {"type": "string"},
                "email": {"type": "string"},
                "plan_interest": {"type": "string"},
                "demo_requested": {"type": "boolean"}
              },
              "required": ["name", "email", "plan_interest", "demo_requested"],
              "additionalProperties": false
            }
          }
        }
      }'
    ```

    Claude возвращает JSON наподобие этого в текстовом блоке содержимого ответа:

    ```json Output
    {
      "name": "John Smith",
      "email": "john@example.com",
      "plan_interest": "Enterprise",
      "demo_requested": true
    }
    ```
  </Tab>

  <Tab title="CLI">
    ```bash
    ant messages create <<'YAML'
    model: claude-opus-5-5
    max_tokens: 1024
    messages:
      - role: user
        content: >-
          Extract the key information from this email: John Smith
          (john@example.com) is interested in our Enterprise plan and wants
          to schedule a demo for next Tuesday at 2pm.
    output_config:
      format:
        type: json_schema
        schema:
          type: object
          properties:
            name: {type: string}
            email: {type: string}
            plan_interest: {type: string}
            demo_requested: {type: boolean}
          required: [name, email, plan_interest, demo_requested]
          additionalProperties: false
    YAML
    ```

    Claude возвращает JSON наподобие этого в текстовом блоке содержимого ответа:

    ```json Output
    {
      "name": "John Smith",
      "email": "john@example.com",
      "plan_interest": "Enterprise",
      "demo_requested": true
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python
    client = anthropic.Anthropic()

    response = client.messages.create(
        model="claude-opus-5-5",
        max_tokens=1024,
        messages=[
            {
                "role": "user",
                "content": (
                    "Extract the key information from this email: "
                    "John Smith (john@example.com) is interested in our Enterprise plan "
                    "and wants to schedule a demo for next Tuesday at 2pm."
                ),
            }
        ],
        output_config={
            "format": {
                "type": "json_schema",
                "schema": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "email": {"type": "string"},
                        "plan_interest": {"type": "string"},
                        "demo_requested": {"type": "boolean"},
                    },
                    "required": ["name", "email", "plan_interest", "demo_requested"],
                    "additionalProperties": False,
                },
            }
        },
    )
    text = next(block.text for block in response.content if block.type == "text")
    contact = json.loads(text)
    print(contact)
    ```

    Предыдущий пример выводит:

    ```text Output wrap
    {'name': 'John Smith', 'email': 'john@example.com', 'plan_interest': 'Enterprise', 'demo_requested': True}
    ```

    Чтобы перенести [ограничения, не поддерживаемые API](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations), в описания полей, пропустите схему через `transform_schema()` из пакета `anthropic` перед отправкой и при необходимости отредактируйте результат. `transform_schema()` также принимает модель Pydantic. В отличие от `client.messages.parse()`, она возвращает преобразованную схему, а не отправляет её.
  </Tab>

  <Tab title="TypeScript">
    ```typescript
    import { jsonSchemaOutputFormat } from "@anthropic-ai/sdk/helpers/json-schema";

    const client = new Anthropic();

    const response = await client.messages.parse({
      model: "claude-opus-5-5",
      max_tokens: 1024,
      messages: [
        {
          role: "user",
          content: "Extract contact info: John Smith, john@example.com, interested in the Pro plan"
        }
      ],
      output_config: {
        format: jsonSchemaOutputFormat({
          type: "object",
          properties: {
            name: { type: "string" },
            email: { type: "string" },
            planInterest: { type: "string" }
          },
          required: ["name", "email", "planInterest"],
          additionalProperties: false
        } as const)
      }
    });

    // response.parsed_output имеет тип { name: string; email: string; planInterest: string } | null
    console.log(response.parsed_output);
    ```

    Используйте `jsonSchemaOutputFormat()`, чтобы передать обычную JSON-схему в `parse()` без установки Zod. API возвращает ответ, соответствующий схеме, и если вы объявите схему с `as const`, TypeScript автоматически выведет тип для `parsed_output` в соответствии с вашей схемой. Для импортированной или сгенерированной схемы `parsed_output` имеет тип `unknown`.

    По умолчанию вспомогательная функция [преобразует схему](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#how-sdk-transformation-works) так же, как `zodOutputFormat()`. Передайте `{ transform: false }` вторым аргументом, чтобы отправить её без изменений. В отличие от `zodOutputFormat()`, она не проверяет ответ, поэтому не обнаруживает нарушения [ограничений, не поддерживаемых API](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations), таких как `minimum`.

    Предыдущий пример выводит:

    ```text Output wrap
    { name: 'John Smith', email: 'john@example.com', planInterest: 'Pro' }
    ```
  </Tab>

  <Tab title="C#">
    ```csharp
    using System.Text.Json;
    using Anthropic;
    using Anthropic.Models.Messages;

    var client = new AnthropicClient();

    var response = await client.Messages.Create(new MessageCreateParams
    {
        Model = Model.ClaudeOpus5_5,
        MaxTokens = 1024,
        Messages = [
            new UserMessageParam
            {
                Content = "Extract the key information from this email: "
                    + "John Smith (john@example.com) is interested in our Enterprise plan "
                    + "and wants to schedule a demo for next Tuesday at 2pm."
            }
        ],
        OutputConfig = new OutputConfig
        {
            Format = new JsonOutputFormat
            {
                Schema = new Dictionary<string, JsonElement>
                {
                    ["type"] = JsonSerializer.SerializeToElement("object"),
                    ["properties"] = JsonSerializer.SerializeToElement(new
                    {
                        name = new { type = "string" },
                        email = new { type = "string" },
                        plan_interest = new { type = "string" },
                        demo_requested = new { type = "boolean" },
                    }),
                    ["required"] = JsonSerializer.SerializeToElement(
                        new[] { "name", "email", "plan_interest", "demo_requested" }),
                    ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
                },
            },
        },
    });

    if (response.Content.Select(block => block.Value).OfType<TextBlock>().FirstOrDefault() is { } textBlock)
    {
        // JSON гарантированно соответствует схеме
        var contact = JsonSerializer.Deserialize<JsonElement>(textBlock.Text);
        Console.WriteLine(contact);
    }
    ```

    Предыдущий пример выводит:

    ```json Output
    {"name":"John Smith","email":"john@example.com","plan_interest":"Enterprise","demo_requested":true}
    ```
  </Tab>

  <Tab title="Go">
    ```go
    type ContactInfo struct {
    	Name          string `json:"name"`
    	Email         string `json:"email"`
    	PlanInterest  string `json:"plan_interest"`
    	DemoRequested bool   `json:"demo_requested"`
    }

    func main() {
    	client := anthropic.NewClient()

    	message, _ := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
    		Model:     anthropic.ModelClaudeOpus5_5,
    		MaxTokens: 1024,
    		Messages: []anthropic.MessageParam{
    			anthropic.NewUserMessage(anthropic.NewTextBlock(
    				"Extract the key information from this email: " +
    					"John Smith (john@example.com) is interested in our Enterprise plan " +
    					"and wants to schedule a demo for next Tuesday at 2pm.",
    			)),
    		},
    		OutputConfig: anthropic.OutputConfigParam{
    			Format: anthropic.JSONOutputFormatParam{
    				Schema: map[string]any{
    					"type": "object",
    					"properties": map[string]any{
    						"name":           map[string]string{"type": "string"},
    						"email":          map[string]string{"type": "string"},
    						"plan_interest":  map[string]string{"type": "string"},
    						"demo_requested": map[string]string{"type": "boolean"},
    					},
    					"required":             []string{"name", "email", "plan_interest", "demo_requested"},
    					"additionalProperties": false,
    				},
    			},
    		},
    	})

    	for _, block := range message.Content {
    		switch variant := block.AsAny().(type) {
    		case anthropic.TextBlock:
    			var contact ContactInfo
    			json.Unmarshal([]byte(variant.Text), &contact)
    			fmt.Printf("%#v\n", contact)
    		}
    	}
    }
    ```

    Предыдущий пример выводит:

    ```text Output wrap
    main.ContactInfo{Name:"John Smith", Email:"john@example.com", PlanInterest:"Enterprise", DemoRequested:true}
    ```

    Чтобы SDK преобразовал схему в виде map, пропустите её через `BetaJSONSchemaOutputFormat()` в бета-API.
  </Tab>

  <Tab title="Java">
    ```java
    import com.anthropic.core.JsonValue;
    import com.anthropic.models.messages.JsonOutputFormat;
    // ...
    import com.anthropic.models.messages.OutputConfig;
    import com.fasterxml.jackson.databind.JsonNode;
    import com.fasterxml.jackson.databind.ObjectMapper;

    void main() throws Exception {
        AnthropicClient client = AnthropicOkHttpClient.fromEnv();

        JsonOutputFormat.Schema schema = JsonOutputFormat.Schema.builder()
            .putAdditionalProperty("type", JsonValue.from("object"))
            .putAdditionalProperty("properties", JsonValue.from(Map.of(
                "name", Map.of("type", "string"),
                "email", Map.of("type", "string"),
                "plan_interest", Map.of("type", "string"))))
            .putAdditionalProperty("required", JsonValue.from(
                List.of("name", "email", "plan_interest")))
            .putAdditionalProperty("additionalProperties", JsonValue.from(false))
            .build();

        OutputConfig outputConfig = OutputConfig.builder()
            .format(JsonOutputFormat.builder()
                .schema(schema)
                .build())
            .build();

        MessageCreateParams createParams = MessageCreateParams.builder()
            .model(Model.CLAUDE_OPUS_5_5)
            .maxTokens(1024)
            .outputConfig(outputConfig)
            .addUserMessage(
                "John Smith (john@example.com) is interested in our Enterprise plan.")
            .build();

        String json = client.messages().create(createParams).content().stream()
            .flatMap(contentBlock -> contentBlock.text().stream())
            .findFirst()
            .orElseThrow()
            .text();

        JsonNode contact = new ObjectMapper().readTree(json);
        IO.println(contact);
    }
    ```

    Предыдущий пример выводит:

    ```json Output
    {"name":"John Smith","email":"john@example.com","plan_interest":"Enterprise"}
    ```

    Более подробный пример, в котором строится вложенная схема с массивами и описаниями, см. в [`StructuredOutputsRawExample.java`](https://github.com/anthropics/anthropic-sdk-java/blob/main/anthropic-java-example/src/main/java/com/anthropic/example/StructuredOutputsRawExample.java) в репозитории SDK.
  </Tab>

  <Tab title="PHP">
    ```php
    use Anthropic\Messages\OutputConfig;
    use Anthropic\Messages\JSONOutputFormat;

    $client = new Client();

    $message = $client->messages->create(
        maxTokens: 1024,
        messages: [
            [
                'role' => 'user',
                'content' => 'Extract the key information from this email: '
                    . 'John Smith (john@example.com) is interested in our Enterprise plan.',
            ],
        ],
        model: 'claude-opus-5-5',
        outputConfig: OutputConfig::with(format: JSONOutputFormat::with(schema: [
            'type' => 'object',
            'properties' => [
                'name' => ['type' => 'string'],
                'email' => ['type' => 'string'],
                'plan_interest' => ['type' => 'string'],
            ],
            'required' => ['name', 'email', 'plan_interest'],
            'additionalProperties' => false,
        ])),
    );

    $textBlock = array_find($message->content, static fn ($block): bool => $block instanceof \Anthropic\Messages\TextBlock)
        ?? throw new \RuntimeException('Expected a text block in the response.');
    $contact = json_decode($textBlock->text, associative: true);
    var_dump($contact);
    ```

    Передайте схему в виде ассоциативного массива в `JSONOutputFormat::with()` внутри `OutputConfig::with()` и декодируйте ответ с помощью `json_decode()`.

    Предыдущий пример выводит:

    ```text Output wrap
    array(3) {
      ["name"]=>
      string(10) "John Smith"
      ["email"]=>
      string(16) "john@example.com"
      ["plan_interest"]=>
      string(10) "Enterprise"
    }
    ```
  </Tab>

  <Tab title="Ruby">
    ```ruby
    client = Anthropic::Client.new

    response = client.messages.create(
      model: Anthropic::Model::CLAUDE_OPUS_5_5,
      max_tokens: 1024,
      messages: [
        {
          role: "user",
          content: "Extract the key information from this email: " \
            "John Smith (john@example.com) is interested in our Enterprise plan " \
            "and wants to schedule a demo for next Tuesday at 2pm."
        }
      ],
      output_config: {
        format: {
          type: "json_schema",
          schema: {
            type: "object",
            properties: {
              name: { type: "string" },
              email: { type: "string" },
              plan_interest: { type: "string" },
              demo_requested: { type: "boolean" }
            },
            required: ["name", "email", "plan_interest", "demo_requested"],
            additionalProperties: false
          }
        }
      }
    )

    text = response.content.find { it.type == :text }.text
    contact = JSON.parse(text)
    p contact
    ```

    Предыдущий пример выводит:

    ```text Output wrap
    {"name" => "John Smith", "email" => "john@example.com", "plan_interest" => "Enterprise", "demo_requested" => true}
    ```
  </Tab>
</Tabs>

## Распространённые сценарии использования

<AccordionGroup>
  <Accordion title="Извлечение данных">
    Извлекайте структурированные данные из неструктурированного текста:

    <CodeGroup>
      ```bash cURL
      curl https://api.anthropic.com/v1/messages \
        -H "content-type: application/json" \
        -H "x-api-key: $ANTHROPIC_API_KEY" \
        -H "anthropic-version: 2026-10-21" \
        -d '{
          "model": "claude-opus-5-5",
          "max_tokens": 4096,
          "messages": [
            {
              "role": "user",
              "content": "Extract invoice data from: Invoice #12345, Date: 2024-01-15, Customer: Acme Corp, 2 widgets at $150.00 each, 1 setup fee at $200.00, Total: $500.00"
            }
          ],
          "output_config": {
            "format": {
              "type": "json_schema",
              "schema": {
                "type": "object",
                "properties": {
                  "invoice_number": {"type": "string"},
                  "date": {"type": "string"},
                  "total_amount": {"type": "number"},
                  "line_items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "description": {"type": "string"},
                        "quantity": {"type": "number"},
                        "unit_price": {"type": "number"}
                      },
                      "required": ["description", "quantity", "unit_price"],
                      "additionalProperties": false
                    }
                  },
                  "customer_name": {"type": "string"}
                },
                "required": ["invoice_number", "date", "total_amount", "line_items", "customer_name"],
                "additionalProperties": false
              }
            }
          }
        }'
      ```

      ```bash CLI
      ant messages create <<'YAML'
      model: claude-opus-5-5
      max_tokens: 4096
      messages:
        - role: user
          content: |
            Extract invoice data from:
            Invoice #12345
            Date: 2024-01-15
            Customer: Acme Corp
            2 widgets at $150.00 each
            1 setup fee at $200.00
            Total: $500.00
      output_config:
        format:
          type: json_schema
          schema:
            type: object
            properties:
              invoice_number: {type: string}
              date: {type: string}
              total_amount: {type: number}
              line_items:
                type: array
                items:
                  type: object
                  properties:
                    description: {type: string}
                    quantity: {type: number}
                    unit_price: {type: number}
                  required: [description, quantity, unit_price]
                  additionalProperties: false
              customer_name: {type: string}
            required: [invoice_number, date, total_amount, line_items, customer_name]
            additionalProperties: false
      YAML
      ```

      ```python Python
      from pydantic import BaseModel


      class LineItem(BaseModel):
          description: str
          quantity: float
          unit_price: float


      class Invoice(BaseModel):
          invoice_number: str
          date: str
          total_amount: float
          line_items: list[LineItem]
          customer_name: str


      client = anthropic.Anthropic()
      invoice_text = """
      Invoice #12345
      Date: 2024-01-15
      Customer: Acme Corp
      2 widgets at $150.00 each
      1 setup fee at $200.00
      Total: $500.00
      """

      response = client.messages.parse(
          model="claude-opus-5-5",
          max_tokens=4096,
          output_format=Invoice,
          messages=[
              {"role": "user", "content": f"Extract invoice data from: {invoice_text}"}
          ],
      )

      print(response.parsed_output)
      ```

      ```typescript TypeScript
      import { z } from "zod";
      import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";

      const client = new Anthropic();

      const LineItemSchema = z.object({
        description: z.string(),
        quantity: z.number(),
        unit_price: z.number()
      });

      const InvoiceSchema = z.object({
        invoice_number: z.string(),
        date: z.string(),
        total_amount: z.number(),
        line_items: z.array(LineItemSchema),
        customer_name: z.string()
      });

      const invoiceText = `
      Invoice #12345
      Date: 2024-01-15
      Customer: Acme Corp
      2 widgets at $150.00 each
      1 setup fee at $200.00
      Total: $500.00
      `;

      const response = await client.messages.parse({
        model: "claude-opus-5-5",
        max_tokens: 4096,
        output_config: { format: zodOutputFormat(InvoiceSchema) },
        messages: [{ role: "user", content: `Extract invoice data from: ${invoiceText}` }]
      });
      console.log(response.parsed_output);
      ```

      ```csharp C#
      AnthropicClient client = new();

      string invoiceText = """
          Invoice #12345
          Date: 2024-01-15
          Customer: Acme Corp
          2 widgets at $150.00 each
          1 setup fee at $200.00
          Total: $500.00
          """;

      var parameters = new MessageCreateParams
      {
          Model = Model.ClaudeOpus5_5,
          MaxTokens = 4096,
          OutputConfig = new OutputConfig
          {
              Format = new JsonOutputFormat
              {
                  Schema = new Dictionary<string, JsonElement>
                  {
                      ["type"] = JsonSerializer.SerializeToElement("object"),
                      ["properties"] = JsonSerializer.SerializeToElement(new
                      {
                          invoice_number = new { type = "string" },
                          date = new { type = "string" },
                          total_amount = new { type = "number" },
                          line_items = new
                          {
                              type = "array",
                              items = new
                              {
                                  type = "object",
                                  properties = new
                                  {
                                      description = new { type = "string" },
                                      quantity = new { type = "number" },
                                      unit_price = new { type = "number" },
                                  },
                                  required = new[] { "description", "quantity", "unit_price" },
                                  additionalProperties = false,
                              },
                          },
                          customer_name = new { type = "string" },
                      }),
                      ["required"] = JsonSerializer.SerializeToElement(new[] { "invoice_number", "date", "total_amount", "line_items", "customer_name" }),
                      ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
                  },
              },
          },
          Messages = [new UserMessageParam { Content = $"Extract invoice data from: {invoiceText}" }]
      };

      var message = await client.Messages.Create(parameters);
      Console.WriteLine(message);
      ```

      ```go Go
      client := anthropic.NewClient()

      invoiceText := `
      Invoice #12345
      Date: 2024-01-15
      Customer: Acme Corp
      2 widgets at $150.00 each
      1 setup fee at $200.00
      Total: $500.00
      `

      schema := map[string]any{
      	"type":                 "object",
      	"additionalProperties": false,
      	"properties": map[string]any{
      		"invoice_number": map[string]any{"type": "string"},
      		"date":           map[string]any{"type": "string"},
      		"total_amount":   map[string]any{"type": "number"},
      		"line_items": map[string]any{
      			"type": "array",
      			"items": map[string]any{
      				"type":                 "object",
      				"additionalProperties": false,
      				"properties": map[string]any{
      					"description": map[string]any{"type": "string"},
      					"quantity":    map[string]any{"type": "number"},
      					"unit_price":  map[string]any{"type": "number"},
      				},
      				"required": []string{"description", "quantity", "unit_price"},
      			},
      		},
      		"customer_name": map[string]any{"type": "string"},
      	},
      	"required": []string{"invoice_number", "date", "total_amount", "line_items", "customer_name"},
      }

      response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
      	Model:     anthropic.ModelClaudeOpus5_5,
      	MaxTokens: 4096,
      	OutputConfig: anthropic.OutputConfigParam{
      		Format: anthropic.JSONOutputFormatParam{
      			Schema: schema,
      		},
      	},
      	Messages: []anthropic.MessageParam{
      		anthropic.NewUserMessage(anthropic.NewTextBlock(fmt.Sprintf("Extract invoice data from: %s", invoiceText))),
      	},
      })
      if err != nil {
      	log.Fatal(err)
      }
      for _, block := range response.Content {
      	switch variant := block.AsAny().(type) {
      	case anthropic.TextBlock:
      		fmt.Println(variant.Text)
      	}
      }
      ```

      ```java Java
      import com.fasterxml.jackson.annotation.JsonProperty;

      static class LineItem {
          @JsonProperty("description")
          public String description;

          @JsonProperty("quantity")
          public double quantity;

          @JsonProperty("unit_price")
          public double unitPrice;
      }

      static class Invoice {
          @JsonProperty("invoice_number")
          public String invoiceNumber;

          @JsonProperty("date")
          public String date;

          @JsonProperty("total_amount")
          public double totalAmount;

          @JsonProperty("line_items")
          public List<LineItem> lineItems;

          @JsonProperty("customer_name")
          public String customerName;
      }

      void main() {
          AnthropicClient client = AnthropicOkHttpClient.fromEnv();

          String invoiceText = """
              Invoice #12345
              Date: 2024-01-15
              Customer: Acme Corp
              2 widgets at $150.00 each
              1 setup fee at $200.00
              Total: $500.00
              """;

          StructuredMessageCreateParams<Invoice> params = MessageCreateParams.builder()
              .model(Model.CLAUDE_OPUS_5_5)
              .maxTokens(4096L)
              .outputConfig(Invoice.class)
              .addUserMessage("Extract invoice data from: " + invoiceText)
              .build();

          StructuredMessage<Invoice> response = client.messages().create(params);
          Invoice invoice = response.content().stream()
              .flatMap(block -> block.text().stream())
              .findFirst().orElseThrow().text();
          IO.println("Invoice " + invoice.invoiceNumber + ": $" + invoice.totalAmount);
          for (LineItem item : invoice.lineItems) {
              IO.println(item.quantity + " x " + item.description);
          }
      }
      ```

      ```php PHP
      use Anthropic\Lib\Attributes\Constrained;
      use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
      use Anthropic\Lib\Contracts\StructuredOutputModel;

      $client = new Client();

      class LineItem implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $description;
          public float $quantity;
          public float $unit_price;
      }

      class Invoice implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $invoice_number;
          public string $date;
          public float $total_amount;
          #[Constrained(itemClass: LineItem::class)]
          public array $line_items;
          public string $customer_name;
      }

      $invoiceText = <<<'TEXT'
      Invoice #12345
      Date: 2024-01-15
      Customer: Acme Corp
      2 widgets at $150.00 each
      1 setup fee at $200.00
      Total: $500.00
      TEXT;

      $message = $client->messages->create(
          maxTokens: 4096,
          messages: [
              ['role' => 'user', 'content' => "Extract invoice data from: $invoiceText"]
          ],
          model: 'claude-opus-5-5',
          outputConfig: ['format' => Invoice::class],
      );

      $invoice = $message->parsedOutput();
      if ($invoice instanceof Invoice) {
          echo "Invoice {$invoice->invoice_number}: \${$invoice->total_amount}\n";
          foreach ($invoice->line_items as $item) {
              echo "{$item->quantity} x {$item->description}\n";
          }
      }
      ```

      ```ruby Ruby
      client = Anthropic::Client.new

      class LineItem < Anthropic::BaseModel
        required :description, String
        required :quantity, Float
        required :unit_price, Float
      end

      class Invoice < Anthropic::BaseModel
        required :invoice_number, String
        required :date, String
        required :total_amount, Float
        required :line_items, Anthropic::ArrayOf[LineItem]
        required :customer_name, String
      end

      invoice_text = <<~TEXT
        Invoice #12345
        Date: 2024-01-15
        Customer: Acme Corp
        2 widgets at $150.00 each
        1 setup fee at $200.00
        Total: $500.00
      TEXT

      message = client.messages.create(
        model: Anthropic::Model::CLAUDE_OPUS_5_5,
        max_tokens: 4096,
        output_config: { format: Invoice },
        messages: [
          { role: "user", content: "Extract invoice data from: #{invoice_text}" }
        ]
      )

      invoice = message.parsed_output
      puts "Invoice #{invoice.invoice_number}: $#{invoice.total_amount}"
      invoice.line_items.each { |item| puts "#{item.quantity} x #{item.description}" }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Классификация">
    Классифицируйте содержимое по структурированным категориям:

    <CodeGroup>
      ```bash cURL
      curl https://api.anthropic.com/v1/messages \
        -H "content-type: application/json" \
        -H "x-api-key: $ANTHROPIC_API_KEY" \
        -H "anthropic-version: 2026-10-21" \
        -d '{
          "model": "claude-opus-5-5",
          "max_tokens": 1024,
          "messages": [
            {
              "role": "user",
              "content": "Classify this feedback: Great product, fast shipping!"
            }
          ],
          "output_config": {
            "format": {
              "type": "json_schema",
              "schema": {
                "type": "object",
                "properties": {
                  "category": {"type": "string"},
                  "confidence": {"type": "number"},
                  "tags": {"type": "array", "items": {"type": "string"}},
                  "sentiment": {"type": "string"}
                },
                "required": ["category", "confidence", "tags", "sentiment"],
                "additionalProperties": false
              }
            }
          }
        }'
      ```

      ```bash CLI
      ant messages create <<'YAML'
      model: claude-opus-5-5
      max_tokens: 1024
      messages:
        - role: user
          content: "Classify this feedback: Great product, fast shipping!"
      output_config:
        format:
          type: json_schema
          schema:
            type: object
            properties:
              category:
                type: string
              confidence:
                type: number
              tags:
                type: array
                items:
                  type: string
              sentiment:
                type: string
            required:
              - category
              - confidence
              - tags
              - sentiment
            additionalProperties: false
      YAML
      ```

      ```python Python
      from pydantic import BaseModel

      client = Anthropic()


      class Classification(BaseModel):
          category: str
          confidence: float
          tags: list[str]
          sentiment: str


      feedback_text = "Great product, but the delivery was slow."
      response = client.messages.parse(
          model="claude-opus-5-5",
          max_tokens=1024,
          output_format=Classification,
          messages=[{"role": "user", "content": f"Classify this feedback: {feedback_text}"}],
      )

      print(response.parsed_output)
      ```

      ```typescript TypeScript
      import { z } from "zod";
      import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";

      const client = new Anthropic();

      const ClassificationSchema = z.object({
        category: z.string(),
        confidence: z.number(),
        tags: z.array(z.string()),
        sentiment: z.string()
      });

      const feedbackText = "Great product, but the delivery was slow.";
      const response = await client.messages.parse({
        model: "claude-opus-5-5",
        max_tokens: 1024,
        output_config: { format: zodOutputFormat(ClassificationSchema) },
        messages: [{ role: "user", content: `Classify this feedback: ${feedbackText}` }]
      });

      console.log(response.parsed_output);
      ```

      ```csharp C#
      AnthropicClient client = new();

      string feedbackText = "Great product, fast shipping!";

      var parameters = new MessageCreateParams
      {
          Model = Model.ClaudeOpus5_5,
          MaxTokens = 1024,
          Messages = [new UserMessageParam { Content = $"Classify this feedback: {feedbackText}" }],
          OutputConfig = new OutputConfig
          {
              Format = new JsonOutputFormat
              {
                  Schema = new Dictionary<string, JsonElement>
                  {
                      ["type"] = JsonSerializer.SerializeToElement("object"),
                      ["properties"] = JsonSerializer.SerializeToElement(new
                      {
                          category = new { type = "string" },
                          confidence = new { type = "number" },
                          tags = new { type = "array", items = new { type = "string" } },
                          sentiment = new { type = "string" },
                      }),
                      ["required"] = JsonSerializer.SerializeToElement(new[] { "category", "confidence", "tags", "sentiment" }),
                      ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
                  },
              },
          },
      };

      var message = await client.Messages.Create(parameters);
      Console.WriteLine(message);
      ```

      ```go Go
      client := anthropic.NewClient()

      feedbackText := "Great product, fast shipping!"

      schema := map[string]any{
      	"type": "object",
      	"properties": map[string]any{
      		"category":   map[string]any{"type": "string"},
      		"confidence": map[string]any{"type": "number"},
      		"tags":       map[string]any{"type": "array", "items": map[string]any{"type": "string"}},
      		"sentiment":  map[string]any{"type": "string"},
      	},
      	"required":             []string{"category", "confidence", "tags", "sentiment"},
      	"additionalProperties": false,
      }

      response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
      	Model:     anthropic.ModelClaudeOpus5_5,
      	MaxTokens: 1024,
      	OutputConfig: anthropic.OutputConfigParam{
      		Format: anthropic.JSONOutputFormatParam{
      			Schema: schema,
      		},
      	},
      	Messages: []anthropic.MessageParam{
      		anthropic.NewUserMessage(anthropic.NewTextBlock(fmt.Sprintf("Classify this feedback: %s", feedbackText))),
      	},
      })
      if err != nil {
      	log.Fatal(err)
      }
      for _, block := range response.Content {
      	switch variant := block.AsAny().(type) {
      	case anthropic.TextBlock:
      		var result map[string]any
      		json.Unmarshal([]byte(variant.Text), &result)
      		fmt.Println(result)
      	}
      }
      ```

      ```java Java
      import com.fasterxml.jackson.annotation.JsonProperty;

      static class Classification {
          @JsonProperty("category")
          public String category;

          @JsonProperty("confidence")
          public double confidence;

          @JsonProperty("tags")
          public List<String> tags;

          @JsonProperty("sentiment")
          public String sentiment;
      }

      void main() {
          AnthropicClient client = AnthropicOkHttpClient.fromEnv();

          String feedbackText = "Great product, fast shipping!";

          StructuredMessageCreateParams<Classification> params = MessageCreateParams.builder()
              .model(Model.CLAUDE_OPUS_5_5)
              .maxTokens(1024L)
              .outputConfig(Classification.class)
              .addUserMessage("Classify this feedback: " + feedbackText)
              .build();

          StructuredMessage<Classification> response = client.messages().create(params);
          Classification result = response.content().stream()
              .flatMap(block -> block.text().stream())
              .findFirst().orElseThrow().text();
          IO.println(result.category + " (" + result.confidence + ")");
      }
      ```

      ```php PHP
      use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
      use Anthropic\Lib\Contracts\StructuredOutputModel;

      $client = new Client();

      class Classification implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $category;
          public float $confidence;
          public array $tags;
          public string $sentiment;
      }

      $feedbackText = 'Great product, fast shipping!';

      $message = $client->messages->create(
          maxTokens: 1024,
          messages: [
              ['role' => 'user', 'content' => "Classify this feedback: {$feedbackText}"]
          ],
          model: 'claude-opus-5-5',
          outputConfig: ['format' => Classification::class],
      );

      $result = $message->parsedOutput();
      if ($result instanceof Classification) {
          echo "{$result->category} ({$result->confidence}): {$result->sentiment}\n";
      }
      ```

      ```ruby Ruby
      client = Anthropic::Client.new

      class Classification < Anthropic::BaseModel
        required :category, String
        required :confidence, Float
        required :tags, Anthropic::ArrayOf[String]
        required :sentiment, String
      end

      feedback_text = "Great product, fast shipping!"

      message = client.messages.create(
        model: Anthropic::Model::CLAUDE_OPUS_5_5,
        max_tokens: 1024,
        output_config: { format: Classification },
        messages: [
          { role: "user", content: "Classify this feedback: #{feedback_text}" }
        ]
      )
      puts message.parsed_output
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Форматирование ответов API">
    Генерируйте ответы, готовые для API:

    <CodeGroup>
      ```bash cURL
      curl https://api.anthropic.com/v1/messages \
        -H "content-type: application/json" \
        -H "x-api-key: $ANTHROPIC_API_KEY" \
        -H "anthropic-version: 2026-10-21" \
        -d '{
          "model": "claude-opus-5-5",
          "max_tokens": 1024,
          "messages": [
            {
              "role": "user",
              "content": "Write an API response: request req_2abc3def has an invalid email."
            }
          ],
          "output_config": {
            "format": {
              "type": "json_schema",
              "schema": {
                "type": "object",
                "properties": {
                  "status": {"type": "string"},
                  "data": {
                    "type": "object",
                    "properties": {"message": {"type": "string"}},
                    "required": ["message"],
                    "additionalProperties": false
                  },
                  "errors": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "code": {"type": "string"},
                        "detail": {"type": "string"}
                      },
                      "required": ["code", "detail"],
                      "additionalProperties": false
                    }
                  },
                  "metadata": {
                    "type": "object",
                    "properties": {"request_id": {"type": "string"}},
                    "required": ["request_id"],
                    "additionalProperties": false
                  }
                },
                "required": ["status", "data", "metadata"],
                "additionalProperties": false
              }
            }
          }
        }'
      ```

      ```bash CLI
      ant messages create <<'YAML'
      model: claude-opus-5-5
      max_tokens: 1024
      output_config:
        format:
          type: json_schema
          schema:
            type: object
            properties:
              status:
                type: string
              data:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
                additionalProperties: false
              errors:
                type: array
                items:
                  type: object
                  properties:
                    code:
                      type: string
                    detail:
                      type: string
                  required:
                    - code
                    - detail
                  additionalProperties: false
              metadata:
                type: object
                properties:
                  request_id:
                    type: string
                required:
                  - request_id
                additionalProperties: false
            required:
              - status
              - data
              - metadata
            additionalProperties: false
      messages:
        - role: user
          content: "Write an API response: request req_2abc3def has an invalid email."
      YAML
      ```

      ```python Python
      from pydantic import BaseModel

      client = Anthropic()


      class Payload(BaseModel):
          message: str


      class APIError(BaseModel):
          code: str
          detail: str


      class Metadata(BaseModel):
          request_id: str


      class APIResponse(BaseModel):
          status: str
          data: Payload
          errors: list[APIError] | None = None
          metadata: Metadata


      response = client.messages.parse(
          model="claude-opus-5-5",
          max_tokens=1024,
          output_format=APIResponse,
          messages=[
              {
                  "role": "user",
                  "content": "Write an API response: request req_2abc3def has an invalid email.",
              }
          ],
      )

      print(response.parsed_output)
      ```

      ```typescript TypeScript
      import { z } from "zod";
      import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";

      const client = new Anthropic();

      const APIResponseSchema = z.object({
        status: z.string(),
        data: z.object({ message: z.string() }),
        errors: z.array(z.object({ code: z.string(), detail: z.string() })).optional(),
        metadata: z.object({ request_id: z.string() })
      });

      const response = await client.messages.parse({
        model: "claude-opus-5-5",
        max_tokens: 1024,
        output_config: { format: zodOutputFormat(APIResponseSchema) },
        messages: [
          {
            role: "user",
            content: "Write an API response: request req_2abc3def has an invalid email."
          }
        ]
      });

      console.log(response.parsed_output);
      ```

      ```csharp C#
      AnthropicClient client = new();

      var parameters = new MessageCreateParams
      {
          Model = Model.ClaudeOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new UserMessageParam
              {
                  Content = "Write an API response: request req_2abc3def has an invalid email.",
              },
          ],
          OutputConfig = new OutputConfig
          {
              Format = new JsonOutputFormat
              {
                  Schema = new Dictionary<string, JsonElement>
                  {
                      ["type"] = JsonSerializer.SerializeToElement("object"),
                      ["properties"] = JsonSerializer.SerializeToElement(new
                      {
                          status = new { type = "string" },
                          data = new
                          {
                              type = "object",
                              properties = new { message = new { type = "string" } },
                              required = new[] { "message" },
                              additionalProperties = false,
                          },
                          errors = new
                          {
                              type = "array",
                              items = new
                              {
                                  type = "object",
                                  properties = new
                                  {
                                      code = new { type = "string" },
                                      detail = new { type = "string" },
                                  },
                                  required = new[] { "code", "detail" },
                                  additionalProperties = false,
                              },
                          },
                          metadata = new
                          {
                              type = "object",
                              properties = new { request_id = new { type = "string" } },
                              required = new[] { "request_id" },
                              additionalProperties = false,
                          },
                      }),
                      ["required"] = JsonSerializer.SerializeToElement(new[] { "status", "data", "metadata" }),
                      ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
                  },
              },
          },
      };

      var message = await client.Messages.Create(parameters);
      Console.WriteLine(message);
      ```

      ```go Go
      client := anthropic.NewClient()

      response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
      	Model:     anthropic.ModelClaudeOpus5_5,
      	MaxTokens: 1024,
      	OutputConfig: anthropic.OutputConfigParam{
      		Format: anthropic.JSONOutputFormatParam{
      			Schema: map[string]any{
      				"type":                 "object",
      				"additionalProperties": false,
      				"properties": map[string]any{
      					"status": map[string]any{
      						"type": "string",
      					},
      					"data": map[string]any{
      						"type":                 "object",
      						"additionalProperties": false,
      						"properties": map[string]any{
      							"message": map[string]any{"type": "string"},
      						},
      						"required": []string{"message"},
      					},
      					"errors": map[string]any{
      						"type": "array",
      						"items": map[string]any{
      							"type":                 "object",
      							"additionalProperties": false,
      							"properties": map[string]any{
      								"code":   map[string]any{"type": "string"},
      								"detail": map[string]any{"type": "string"},
      							},
      							"required": []string{"code", "detail"},
      						},
      					},
      					"metadata": map[string]any{
      						"type":                 "object",
      						"additionalProperties": false,
      						"properties": map[string]any{
      							"request_id": map[string]any{"type": "string"},
      						},
      						"required": []string{"request_id"},
      					},
      				},
      				"required": []string{"status", "data", "metadata"},
      			},
      		},
      	},
      	Messages: []anthropic.MessageParam{
      		anthropic.NewUserMessage(anthropic.NewTextBlock(
      			"Write an API response: request req_2abc3def has an invalid email.",
      		)),
      	},
      })
      if err != nil {
      	log.Fatal(err)
      }
      for _, block := range response.Content {
      	switch variant := block.AsAny().(type) {
      	case anthropic.TextBlock:
      		fmt.Println(variant.Text)
      	}
      }
      ```

      ```java Java
      import com.fasterxml.jackson.annotation.JsonProperty;

      static class Payload {
          @JsonProperty("message")
          public String message;
      }

      static class APIError {
          @JsonProperty("code")
          public String code;

          @JsonProperty("detail")
          public String detail;
      }

      static class Metadata {
          @JsonProperty("request_id")
          public String requestId;
      }

      static class APIResponse {
          @JsonProperty("status")
          public String status;

          @JsonProperty("data")
          public Payload data;

          @JsonProperty("errors")
          public List<APIError> errors;

          @JsonProperty("metadata")
          public Metadata metadata;
      }

      void main() {
          AnthropicClient client = AnthropicOkHttpClient.fromEnv();

          StructuredMessageCreateParams<APIResponse> params = MessageCreateParams.builder()
              .model(Model.CLAUDE_OPUS_5_5)
              .maxTokens(1024L)
              .outputConfig(APIResponse.class)
              .addUserMessage("Write an API response: request req_2abc3def has an invalid email.")
              .build();

          StructuredMessage<APIResponse> response = client.messages().create(params);
          APIResponse result = response.content().stream()
              .flatMap(block -> block.text().stream())
              .findFirst().orElseThrow().text();
          IO.println(result.status + ": " + result.data.message);
      }
      ```

      ```php PHP
      use Anthropic\Lib\Attributes\Constrained;
      use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
      use Anthropic\Lib\Contracts\StructuredOutputModel;

      $client = new Client();

      class Payload implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $message;
      }

      class APIError implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $code;
          public string $detail;
      }

      class Metadata implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $request_id;
      }

      class APIResponse implements StructuredOutputModel
      {
          use StructuredOutputModelTrait;

          public string $status;
          public Payload $data;
          #[Constrained(itemClass: APIError::class)]
          public ?array $errors;
          public Metadata $metadata;
      }

      $message = $client->messages->create(
          maxTokens: 1024,
          messages: [
              [
                  'role' => 'user',
                  'content' => 'Write an API response: request req_2abc3def has an invalid email.',
              ],
          ],
          model: 'claude-opus-5-5',
          outputConfig: ['format' => APIResponse::class],
      );

      $result = $message->parsedOutput();
      if ($result instanceof APIResponse) {
          echo "{$result->status}: {$result->data->message}\n";
      }
      ```

      ```ruby Ruby
      client = Anthropic::Client.new

      class Payload < Anthropic::BaseModel
        required :message, String
      end

      class APIError < Anthropic::BaseModel
        required :code, String
        required :detail, String
      end

      class Metadata < Anthropic::BaseModel
        required :request_id, String
      end

      class APIResponse < Anthropic::BaseModel
        required :status, String
        required :data, Payload
        optional :errors, Anthropic::ArrayOf[APIError]
        required :metadata, Metadata
      end

      message = client.messages.create(
        model: Anthropic::Model::CLAUDE_OPUS_5_5,
        max_tokens: 1024,
        output_config: { format: APIResponse },
        messages: [
          { role: "user", content: "Write an API response: request req_2abc3def has an invalid email." }
        ]
      )
      puts message.parsed_output
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Строгое использование инструментов

Чтобы обеспечить соответствие входных данных инструментов JSON Schema с помощью выборки, ограниченной грамматикой, см. [Строгое использование инструментов](https://platform.claude.com/docs/ru/agents-and-tools/tool-use/strict-tool-use).

### Совместное использование обеих функций

Выходные данные JSON и строгое использование инструментов решают разные задачи и работают вместе:

* **Выходные данные JSON** управляют форматом ответа Claude (что говорит Claude).
* **Строгое использование инструментов** проверяет параметры инструментов (как Claude вызывает ваши функции).

При совместном использовании Claude может вызывать инструменты с гарантированно корректными параметрами И возвращать структурированные ответы JSON. Это полезно для агентных рабочих процессов, где вам нужны как надёжные вызовы инструментов, так и структурированные итоговые выходные данные.

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2026-10-21" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": "Help me plan a trip to Paris departing May 15, 2026"
        }
      ],
      "output_config": {
        "format": {
          "type": "json_schema",
          "schema": {
            "type": "object",
            "properties": {
              "summary": {"type": "string"},
              "next_steps": {"type": "array", "items": {"type": "string"}}
            },
            "required": ["summary", "next_steps"],
            "additionalProperties": false
          }
        }
      },
      "tools": [
        {
          "name": "search_flights",
          "strict": true,
          "input_schema": {
            "type": "object",
            "properties": {
              "destination": {"type": "string"},
              "date": {"type": "string", "format": "date"}
            },
            "required": ["destination", "date"],
            "additionalProperties": false
          }
        }
      ]
    }'
  ```

  ```bash CLI
  ant messages create <<'YAML'
  model: claude-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content: Help me plan a trip to Paris departing May 15, 2026
  # Выходные данные JSON: структурированный формат ответа
  output_config:
    format:
      type: json_schema
      schema:
        type: object
        properties:
          summary:
            type: string
          next_steps:
            type: array
            items:
              type: string
        required: [summary, next_steps]
        additionalProperties: false
  # Строгое использование инструментов: гарантированные параметры инструментов
  tools:
    - name: search_flights
      strict: true
      input_schema:
        type: object
        properties:
          destination:
            type: string
          date:
            type: string
            format: date
        required: [destination, date]
        additionalProperties: false
  YAML
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": "Help me plan a trip to Paris departing May 15, 2026",
          }
      ],
      # Выходные данные JSON: структурированный формат ответа
      output_config={
          "format": {
              "type": "json_schema",
              "schema": {
                  "type": "object",
                  "properties": {
                      "summary": {"type": "string"},
                      "next_steps": {"type": "array", "items": {"type": "string"}},
                  },
                  "required": ["summary", "next_steps"],
                  "additionalProperties": False,
              },
          }
      },
      # Строгое использование инструментов: гарантированные параметры инструментов
      tools=[
          {
              "name": "search_flights",
              "strict": True,
              "input_schema": {
                  "type": "object",
                  "properties": {
                      "destination": {"type": "string"},
                      "date": {"type": "string", "format": "date"},
                  },
                  "required": ["destination", "date"],
                  "additionalProperties": False,
              },
          }
      ],
  )

  print(response)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Help me plan a trip to Paris departing May 15, 2026" }],
    // Выходные данные JSON: структурированный формат ответа
    output_config: {
      format: {
        type: "json_schema",
        schema: {
          type: "object",
          properties: {
            summary: { type: "string" },
            next_steps: { type: "array", items: { type: "string" } }
          },
          required: ["summary", "next_steps"],
          additionalProperties: false
        }
      }
    },
    // Строгое использование инструментов: гарантированные параметры инструментов
    tools: [
      {
        name: "search_flights",
        description: "Search for available flights to a destination on a specific date",
        strict: true,
        input_schema: {
          type: "object",
          properties: {
            destination: { type: "string" },
            date: { type: "string", format: "date" }
          },
          required: ["destination", "date"],
          additionalProperties: false
        }
      }
    ]
  });

  // Claude может сначала вызвать инструмент (tool_use) или ответить в формате JSON (text)
  console.log("Stop reason:", response.stop_reason);
  for (const block of response.content) {
    switch (block.type) {
      case "tool_use":
        console.log(`Tool call: ${block.name}(${JSON.stringify(block.input)})`);
        break;
      case "text":
        console.log("Response:", block.text);
        break;
    }
  }
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 1024,
      Messages = [new UserMessageParam { Content = "Help me plan a trip to Paris departing May 15, 2026" }],
      // JSON outputs (выходные данные в формате JSON): структурированный формат ответа
      OutputConfig = new OutputConfig
      {
          Format = new JsonOutputFormat
          {
              Schema = new Dictionary<string, JsonElement>
              {
                  ["type"] = JsonSerializer.SerializeToElement("object"),
                  ["properties"] = JsonSerializer.SerializeToElement(new
                  {
                      summary = new { type = "string" },
                      next_steps = new { type = "array", items = new { type = "string" } },
                  }),
                  ["required"] = JsonSerializer.SerializeToElement(new[] { "summary", "next_steps" }),
                  ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
              },
          },
      },
      // Strict tool use (строгое использование инструментов): гарантированные параметры инструментов
      Tools =
      [
          new Tool
          {
              Name = "search_flights",
              Strict = true,
              InputSchema = new InputSchema(new Dictionary<string, JsonElement>
              {
                  ["properties"] = JsonSerializer.SerializeToElement(new Dictionary<string, object>
                  {
                      ["destination"] = new { type = "string" },
                      ["date"] = new { type = "string", format = "date" },
                  }),
                  ["required"] = JsonSerializer.SerializeToElement(new[] { "destination", "date" }),
                  ["additionalProperties"] = JsonSerializer.SerializeToElement(false),
              }),
          }
      ],
  };

  var message = await client.Messages.Create(parameters);
  Console.WriteLine(message);
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 1024,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Help me plan a trip to Paris departing May 15, 2026")),
  	},
  	// Выходные данные JSON: структурированный формат ответа
  	OutputConfig: anthropic.OutputConfigParam{
  		Format: anthropic.JSONOutputFormatParam{
  			Schema: map[string]any{
  				"type":                 "object",
  				"additionalProperties": false,
  				"properties": map[string]any{
  					"summary":    map[string]any{"type": "string"},
  					"next_steps": map[string]any{"type": "array", "items": map[string]any{"type": "string"}},
  				},
  				"required": []string{"summary", "next_steps"},
  			},
  		},
  	},
  	// Строгое использование инструментов: гарантированные параметры инструментов
  	Tools: []anthropic.ToolUnionParam{
  		{OfTool: &anthropic.ToolParam{
  			Name:   "search_flights",
  			Strict: anthropic.Bool(true),
  			InputSchema: anthropic.ToolInputSchemaParam{
  				Properties: map[string]any{
  					"destination": map[string]any{"type": "string"},
  					"date":        map[string]any{"type": "string", "format": "date"},
  				},
  				Required: []string{"destination", "date"},
  				ExtraFields: map[string]any{
  					"additionalProperties": false,
  				},
  			}}},
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response.Content)
  ```

  ```java Java
  AnthropicClient client = AnthropicOkHttpClient.fromEnv();

  // Вывод JSON: структурированный формат ответа
  JsonOutputFormat.Schema outputSchema = JsonOutputFormat.Schema.builder()
      .putAdditionalProperty("type", JsonValue.from("object"))
      .putAdditionalProperty("properties", JsonValue.from(Map.of(
          "summary", Map.of("type", "string"),
          "next_steps", Map.of("type", "array", "items", Map.of("type", "string"))
      )))
      .putAdditionalProperty("required", JsonValue.from(List.of("summary", "next_steps")))
      .putAdditionalProperty("additionalProperties", JsonValue.from(false))
      .build();

  // Строгое использование инструментов: гарантированные параметры инструментов
  InputSchema toolSchema = InputSchema.builder()
      .properties(JsonValue.from(Map.of(
          "destination", Map.of("type", "string"),
          "date", Map.of("type", "string", "format", "date")
      )))
      .putAdditionalProperty("required", JsonValue.from(List.of("destination", "date")))
      .putAdditionalProperty("additionalProperties", JsonValue.from(false))
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.CLAUDE_OPUS_5_5)
      .maxTokens(1024L)
      .addUserMessage("Help me plan a trip to Paris departing May 15, 2026")
      .outputConfig(OutputConfig.builder()
          .format(JsonOutputFormat.builder()
              .schema(outputSchema)
              .build())
          .build())
      .addTool(Tool.builder()
          .name("search_flights")
          .description("Search for available flights to a destination on a specific date")
          .strict(true)
          .inputSchema(toolSchema)
          .build())
      .build();

  Message response = client.messages().create(params);
  IO.println(response);
  ```

  ```php PHP
  use Anthropic\Lib\Concerns\StructuredOutputModelTrait;
  use Anthropic\Lib\Contracts\StructuredOutputModel;
  use Anthropic\Messages\ToolUseBlock;

  $client = new Client();

  class TripPlan implements StructuredOutputModel
  {
      use StructuredOutputModelTrait;

      public string $summary;
      public array $next_steps;
  }

  $message = $client->messages->create(
      maxTokens: 1024,
      messages: [
          ['role' => 'user', 'content' => 'Help me plan a trip to Paris departing May 15, 2026']
      ],
      model: 'claude-opus-5-5',
      // Выходные данные JSON: структурированный формат ответа
      outputConfig: ['format' => TripPlan::class],
      // Строгое использование инструментов: гарантированные параметры инструментов
      tools: [
          [
              'name' => 'search_flights',
              'strict' => true,
              'input_schema' => [
                  'type' => 'object',
                  'properties' => [
                      'destination' => ['type' => 'string'],
                      'date' => ['type' => 'string', 'format' => 'date']
                  ],
                  'required' => ['destination', 'date'],
                  'additionalProperties' => false
              ]
          ]
      ],
  );

  // Claude может сначала вызвать инструмент (tool_use) или ответить в формате JSON (text)
  $plan = $message->parsedOutput();
  if ($plan instanceof TripPlan) {
      echo $plan->summary, "\n";
  } elseif ($toolUse = array_find($message->content, fn($block) => $block instanceof ToolUseBlock)) {
      echo "Tool call: {$toolUse->name}(", json_encode($toolUse->input), ")\n";
  }
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: Anthropic::Model::CLAUDE_OPUS_5_5,
    max_tokens: 1024,
    messages: [
      { role: "user", content: "Help me plan a trip to Paris departing May 15, 2026" }
    ],
    # Выходные данные JSON: структурированный формат ответа
    output_config: {
      format: {
        type: :json_schema,
        schema: {
          type: "object",
          properties: {
            summary: { type: "string" },
            next_steps: { type: "array", items: { type: "string" } }
          },
          required: ["summary", "next_steps"],
          additionalProperties: false
        }
      }
    },
    # Строгое использование инструментов: гарантированные параметры инструментов
    tools: [
      {
        name: "search_flights",
        strict: true,
        input_schema: {
          type: "object",
          properties: {
            destination: { type: "string" },
            date: { type: "string", format: "date" }
          },
          required: ["destination", "date"],
          additionalProperties: false
        }
      }
    ]
  )
  puts message
  ```
</CodeGroup>

## Важные соображения

### Компиляция грамматики и кэширование

Структурированные выходные данные используют ограниченную выборку со скомпилированными артефактами грамматики. Это приводит к некоторым характеристикам производительности, о которых следует знать:

* **Задержка первого запроса:** при первом использовании определённой схемы возникает дополнительная задержка (latency), пока компилируется грамматика.
* **Автоматическое кэширование:** скомпилированные грамматики кэшируются на 24 часа с момента последнего использования, что значительно ускоряет последующие запросы.
* **Аннулирование кэша:** кэш аннулируется, если вы меняете структуру JSON-схемы или, при совместном использовании структурированных выходных данных и использования инструментов, набор инструментов в запросе. Изменение только полей `name` или `description` не аннулирует кэш.

### Изменение подсказки и стоимость токенов

При использовании структурированных выходных данных Claude автоматически получает дополнительную системную подсказку (system prompt), объясняющую ожидаемый формат вывода. Это означает:

* Количество входных токенов немного увеличивается.
* Внедрённая подсказка расходует токены так же, как любая другая системная подсказка.
* Изменение параметра `output_config.format` аннулирует любой [кэш подсказок](https://platform.claude.com/docs/ru/build-with-claude/prompt-caching) для этой ветки диалога.

### Ограничения JSON Schema

Структурированные выходные данные поддерживают стандартную JSON Schema с некоторыми ограничениями. Эти ограничения общие для выходных данных JSON и строгого использования инструментов.

<Accordion title="Поддерживаемые возможности">
  * Все базовые типы: object, array, string, integer, number, boolean, null
  * `enum` и `const` (только строки, числа, логические значения или null), с [оговоркой относительно регистра](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#invalid-outputs)
  * `anyOf` и `allOf`, за исключением случаев, перечисленных в разделе «Не поддерживается»
  * `$ref`, `$defs` и `definitions`
  * Свойство `default` для всех поддерживаемых типов
  * `required` и `additionalProperties` (для объектов должно быть установлено в `false`)
  * Строковые форматы: `date-time`, `time`, `date`, `duration`, `email`, `hostname`, `uri`, `ipv4`, `ipv6`, `uuid`
  * `minItems` для массивов (поддерживаются только значения 0 и 1)
</Accordion>

<Accordion title="Не поддерживается">
  * Рекурсивные схемы
  * `oneOf` (используйте вместо него `anyOf`)
  * `not`
  * `anyOf` в том же объекте схемы, что и ключевые слова, такие как `type` или `properties` (аннотации, такие как `title` и `description`, допустимы)
  * `allOf` с конфликтующими схемами (например, с разными значениями `type`)
  * `allOf` с двумя или более схемами, если одна из них напрямую содержит `$ref`, `anyOf` или `allOf`
  * Сложные типы внутри перечислений
  * Внешний `$ref` (например, `'$ref': 'http://...'`)
  * Числовые ограничения (такие как `minimum`, `maximum`, `multipleOf`)
  * Строковые ограничения (`minLength`, `maxLength`)
  * Ограничения массивов, кроме `minItems` со значением 0 или 1
  * `additionalProperties` со значением, отличным от `false` (см. [Объекты с произвольными ключами](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#objects-with-arbitrary-keys))

  Если вы используете неподдерживаемую возможность, вы получите ошибку 400 с подробностями.
</Accordion>

<Accordion title="Поддержка шаблонов (regex)">
  **Поддерживаемые возможности регулярных выражений:**

  * Полное совпадение (`^...$`) и частичное совпадение
  * Квантификаторы: `*`, `+`, `?`, простые случаи `{n,m}`
  * Классы символов: `[]`, `.`, `\d`, `\w`, `\s`
  * Группы: `(...)`

  **Не поддерживается:**

  * Обратные ссылки на группы (например, `\1`, `\2`)
  * Утверждения просмотра вперёд/назад (например, `(?=...)`, `(?!...)`)
  * Границы слов: `\b`, `\B`
  * Сложные квантификаторы `{n,m}` с большими диапазонами

  Простые шаблоны регулярных выражений работают хорошо. Сложные шаблоны могут приводить к ошибкам 400.
</Accordion>

<Tip>
  Вспомогательные функции SDK могут преобразовывать схемы с [ограничениями, не поддерживаемыми API](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#json-schema-limitations). См. [Как работает преобразование в SDK](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#how-sdk-transformation-works).
</Tip>

#### Объекты с произвольными ключами

Перечислите каждый ключ объекта — либо в `properties`, либо как поле класса или схемы, которые вы передаёте в SDK. Поскольку `additionalProperties` должно быть `false`, Claude может вернуть только перечисленные вами ключи.

API принимает объект с пустым или отсутствующим `properties`, но Claude может вернуть для него только `{}`. Тип map, словаря или record не перечисляет ключей, поэтому SDK для Python и TypeScript отправляют его как объект с пустым `properties`. SDK для Java и Ruby вместо этого выдают ошибку.

Если ключи заранее неизвестны, используйте вместо этого массив. Задайте каждому элементу `key` и `value`, как в этой схеме:

```json
{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "key": { "type": "string" },
      "value": { "type": "string" }
    },
    "required": ["key", "value"],
    "additionalProperties": false
  }
}
```

### Порядок свойств

При использовании структурированных выходных данных свойства в объектах сохраняют порядок, определённый в вашей схеме, с одной важной оговоркой: **сначала идут обязательные свойства, затем необязательные**.

Например, для такой схемы:

```json
{
  "type": "object",
  "properties": {
    "notes": { "type": "string" },
    "name": { "type": "string" },
    "email": { "type": "string" },
    "age": { "type": "integer" }
  },
  "required": ["name", "email"],
  "additionalProperties": false
}
```

В выводе свойства упорядочиваются так:

1. `name` (обязательное, в порядке схемы)
2. `email` (обязательное, в порядке схемы)
3. `notes` (необязательное, в порядке схемы)
4. `age` (необязательное, в порядке схемы)

Это означает, что вывод может выглядеть так:

```json
{
  "name": "John Smith",
  "email": "john@example.com",
  "notes": "Interested in enterprise plan",
  "age": 35
}
```

Если порядок свойств в выводе важен для вашего приложения, пометьте все свойства как обязательные или учитывайте это переупорядочивание в логике разбора.

### Недопустимые выходные данные

Хотя структурированные выходные данные в большинстве случаев гарантируют соответствие схеме, существуют сценарии, в которых вывод может не соответствовать вашей схеме:

**Отказы** (`stop_reason: "refusal"`)

Claude сохраняет свои свойства безопасности и полезности даже при использовании структурированных выходных данных. Если Claude отказывается выполнить запрос по соображениям безопасности:

* Ответ содержит `stop_reason: "refusal"`.
* Вы получите код состояния 200.
* Вам будет выставлен счёт за сгенерированные токены.
* Вывод может не соответствовать вашей схеме, поскольку сообщение об отказе имеет приоритет над ограничениями схемы.

Свойство, запрашивающее размышления (thinking) модели или пошаговые рассуждения, может привести к отказу `reasoning_extraction`. Вместо этого запрашивайте краткое объяснение. См. [Храните рассуждения в блоках размышлений](https://platform.claude.com/docs/ru/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks).

**Достигнут лимит токенов** (`stop_reason: "max_tokens"`)

Если ответ обрезан из-за достижения лимита `max_tokens`:

* Ответ содержит `stop_reason: "max_tokens"`.
* Вывод может быть неполным и не соответствовать вашей схеме.
* Повторите запрос с большим значением `max_tokens`, чтобы получить полные структурированные выходные данные.

**Регистр значений перечислений**

Структурированные выходные данные не гарантируют регистр строковых значений `enum` и `const`: Claude может вернуть значение, которое отличается от указанного в схеме только регистром, обычно в первой букве слова после пробела. Например, для такой схемы:

```json
{
  "type": "string",
  "enum": ["Conversation Topic 1", "Conversation Topic 2", "Conversation topic 3"]
}
```

Вывод может содержать `"Conversation Topic 3"` (с заглавной «T»), даже если такого точного значения нет в перечислении. Ответ завершается нормально, без ошибки и без особого `stop_reason`. Это относится как к выходным данным JSON, так и к строгому использованию инструментов. Сравнивайте значения перечислений без учёта регистра и избегайте значений перечислений, которые отличаются только регистром.

### Ограничения сложности схем

Структурированные выходные данные работают путём компиляции ваших JSON-схем в грамматику, которая ограничивает вывод Claude. Более сложные схемы создают более крупные грамматики, компиляция которых занимает больше времени. Для защиты от чрезмерного времени компиляции API применяет несколько ограничений сложности.

#### Явные ограничения

Следующие ограничения применяются ко всем запросам с `output_config.format` или `strict: true`:

| Ограничение                    | Значение | Описание                                                                                                                                                                                                              |
| ------------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Строгих инструментов на запрос | 20       | Максимальное количество инструментов с `strict: true`. Нестрогие инструменты не учитываются в этом ограничении.                                                                                                       |
| Необязательные параметры       | 24       | Общее количество необязательных параметров во всех схемах строгих инструментов и схемах выходных данных JSON. Каждый параметр, не указанный в `required`, учитывается в этом ограничении.                             |
| Параметры с типами объединений | 16       | Общее количество параметров, использующих `anyOf` или массивы типов (например, `"type": ["string", "null"]`), во всех строгих схемах. Они особенно затратны, поскольку создают экспоненциальную стоимость компиляции. |

<Note>
  Эти ограничения применяются к суммарному количеству во всех строгих схемах в одном запросе. Например, если у вас четыре строгих инструмента по шесть необязательных параметров в каждом, вы достигнете ограничения в 24 параметра, даже если ни один инструмент по отдельности не выглядит сложным.
</Note>

#### Дополнительные внутренние ограничения

Помимо явных ограничений из приведённой выше таблицы, существуют дополнительные внутренние ограничения на размер скомпилированной грамматики. Эти ограничения существуют потому, что сложность схемы не сводится к одному измерению: такие возможности, как необязательные параметры, типы объединений, вложенные объекты и количество инструментов, взаимодействуют друг с другом так, что скомпилированная грамматика может стать непропорционально большой.

При превышении этих ограничений вы получите ошибку 400 с сообщением «Schema is too complex for compilation.» Такие ошибки означают, что совокупная сложность ваших схем превышает то, что можно эффективно скомпилировать, даже если каждое отдельное ограничение из приведённой выше таблицы соблюдено. В качестве последней меры API также применяет **тайм-аут компиляции в 180 секунд**. Схемы, которые проходят все явные проверки, но создают очень большие скомпилированные грамматики, могут достичь этого тайм-аута.

#### Советы по снижению сложности схем

Если вы сталкиваетесь с ограничениями сложности, попробуйте следующие стратегии по порядку:

1. **Помечайте как строгие только критически важные инструменты.** Если у вас много инструментов, используйте строгое использование инструментов только для тех, где нарушения схемы вызывают реальные проблемы, а для более простых инструментов полагайтесь на естественное соблюдение схемы Claude.

2. **Сократите число необязательных параметров.** По возможности делайте параметры `required`. Каждый необязательный параметр примерно удваивает часть пространства состояний грамматики. Если у параметра всегда есть разумное значение по умолчанию, рассмотрите возможность сделать его обязательным и попросить Claude явно указывать это значение.

3. **Упростите вложенные структуры.** Глубоко вложенные объекты с необязательными полями усугубляют сложность. По возможности делайте структуры плоскими.

4. **Разделите на несколько запросов.** Если у вас много строгих инструментов, рассмотрите возможность распределить их по отдельным запросам или субагентам.

При устойчивых проблемах с корректными схемами [обратитесь в службу поддержки](https://support.claude.com/en/articles/9015913-how-to-get-support), приложив определение вашей схемы.

## Миграция с бета-версии

Параметр `output_format` перенесён в `output_config.format`, и бета-заголовки больше не требуются. Параметр `output_format` устарел. Чтобы всё же использовать его, добавьте бета-заголовок `structured-outputs-2025-11-13`. Без него API возвращает ошибку 400.

В Python SDK (v1.0 и новее) словарь схемы, переданный как `output_format={...}`, вызывает `TypeError`. Вместо этого используйте `output_config`. Модель Pydantic, переданная как `output_format=Model` в `parse()` или `stream()`, работает без изменений и без бета-заголовка, поскольку SDK отправляет её как `output_config`. Обновлённую структуру API см. в разделе [Использование необработанной JSON-схемы](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#using-a-raw-json-schema).

## Совместимость функций

**Работает с:**

* **[Пакетная обработка](https://platform.claude.com/docs/ru/build-with-claude/batch-processing):** обрабатывайте структурированные выходные данные в масштабе со скидкой 50 процентов
* **[Подсчёт токенов](https://platform.claude.com/docs/ru/build-with-claude/token-counting):** подсчитывайте токены без компиляции
* **[Потоковая передача](https://platform.claude.com/docs/ru/build-with-claude/streaming):** передавайте структурированные выходные данные потоком, как обычные ответы
* **[Совместное использование](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#using-both-features-together):** используйте выходные данные JSON (`output_config.format`) и строгое использование инструментов (`strict: true`) вместе в одном запросе

**Несовместимо с:**

* **[Цитаты](https://platform.claude.com/docs/ru/build-with-claude/citations):** цитаты требуют чередования блоков цитат с текстом, что противоречит строгим ограничениям JSON-схемы. API возвращает ошибку 400, если цитаты включены вместе с `output_config.format`. Чтобы извлечь структурированные данные с цитатой для каждого значения, см. [Получение структурированных данных с цитатами](https://platform.claude.com/docs/ru/build-with-claude/citations#get-structured-data-with-citations).
* **Предварительное заполнение сообщений:** предварительное заполнение несовместимо с выходными данными JSON.

<Tip>
  **Область действия грамматики:** грамматики применяются только к прямому выводу Claude, но не к вызовам инструментов, результатам инструментов или тегам размышлений (при использовании [размышлений](https://platform.claude.com/docs/ru/build-with-claude/thinking)). Состояние грамматики сбрасывается между разделами, что позволяет Claude свободно размышлять, при этом создавая структурированный вывод в итоговом ответе.
</Tip>

## Доступность

Структурированные выходные данные находятся в доступе для всех моделей и подпадают под готовность к HIPAA.

### Поддержка API

#### [Messages API](https://platform.claude.com/docs/ru/build-with-claude/working-with-messages)

* Доступность: Доступно

| Статус   | Облачные платформы           | Модели                                                            |
| -------- | ---------------------------- | ----------------------------------------------------------------- |
| Доступно | Все поддерживаемые платформы | [Все модели](https://platform.claude.com/docs/ru/models/overview) |

#### [Managed Agents](https://platform.claude.com/docs/ru/managed-agents/overview)

* Доступность: Недоступно

### Обработка данных

[Обзор обработки данных](https://platform.claude.com/docs/ru/manage-claude/api-and-data-retention#feature-eligibility)

| Элемент     | Нулевое хранение данных                                                                                                                                                                                                                                                                                                                                                             | HIPAA                                                                                                                                                                                              |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Статус      | Допускается (с оговорками; кроме [Охватываемые модели](https://platform.claude.com/docs/ru/manage-claude/api-and-data-retention#model-specific-data-retention-requirements))                                                                                                                                                                                                        | Допускается                                                                                                                                                                                        |
| Подробности | Ваши подсказки и выходные данные Claude не хранятся. Кэшируется только JSON-схема — до 24 часов с момента последнего использования. Это также относится к строгому использованию инструментов (`strict: true` для инструментов), которое использует тот же конвейер грамматик. [Подробнее](https://platform.claude.com/docs/ru/build-with-claude/structured-outputs#data-retention) | PHI не должна включаться в определения JSON-схем; см. рекомендации по обработке PHI. [Подробнее](https://platform.claude.com/docs/ru/manage-claude/api-and-data-retention#phi-handling-guidelines) |

Применимые конечные точки:

* `/v1/messages`

Подсказки и ответы обрабатываются с ZDR при использовании структурированных выходных данных. Однако сама JSON-схема временно кэшируется на срок до 24 часов с момента последнего использования в целях оптимизации. Никакие данные подсказок или ответов не сохраняются после ответа API.

Структурированные выходные данные допускаются для HIPAA, однако **PHI не должна включаться в определения JSON-схем**. API компилирует JSON-схемы в грамматики, которые кэшируются отдельно от содержимого сообщений, и эти кэшированные схемы не получают той же защиты PHI, что подсказки и ответы. Не включайте PHI в имена свойств схемы, значения `enum`, значения `const` или регулярные выражения `pattern`. PHI должна присутствовать только в содержимом сообщений (подсказках и ответах), где она защищена мерами безопасности HIPAA.

## Дальнейшие шаги

<CardGroup cols={2}>
  <Card title="Цитаты" icon="book-bookmark" href="https://platform.claude.com/docs/ru/build-with-claude/citations">
    Позвольте Claude ссылаться на источники при ответах на вопросы о предоставленных документах.
  </Card>

  <Card title="Строгое использование инструментов" icon="check" href="https://platform.claude.com/docs/ru/agents-and-tools/tool-use/strict-tool-use">
    Обеспечьте соответствие входных данных инструментов Claude JSON Schema с помощью выборки, ограниченной грамматикой.
  </Card>

  <Card title="Использование инструментов с Claude" icon="wrench" href="https://platform.claude.com/docs/ru/agents-and-tools/tool-use/overview">
    Подключайте Claude к внешним инструментам и API. Узнайте, где выполняются инструменты и как работает агентный цикл.
  </Card>

  <Card title="Цены" icon="calculator" href="https://platform.claude.com/docs/ru/about-claude/pricing">
    Узнайте о структуре цен Anthropic на модели и функции.
  </Card>
</CardGroup>
