Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex AI Studio
  • Getting started with Model Gallery
    • About Yandex AI Studio
      • Overview
      • Common instance models
      • Dedicated instance models
      • Batch processing
      • Function calling
      • Reasoning mode
      • Formatting model responses
      • Embeddings
      • Datasets
      • Fine-tuning
      • Tokens
    • Yandex Workflows
    • Quotas and limits
    • Terms and definitions
  • Switching from the AI Assistant API to Responses API
  • Compatibility with OpenAI
  • Access management
  • Pricing policy
  • Audit Trails events
  • Public materials
  • Release notes
  1. Concepts
  2. Model Gallery
  3. Formatting model responses

Formatting model responses

Written by
Yandex Cloud
Updated at December 3, 2025

By default, the model returns a response formatted with Markdown. Use the prompt text to get a response with additional formatting, e.g., with emoji, or in a different format, e.g., JSON, XML, etc.

Here is an example:

{
  "modelUri": "gpt://<folder_ID>/yandexgpt/latest",
  "completionOptions": {
    "stream": false,
    "temperature": 0.6,
    "maxTokens": "2000",
    "reasoningOptions": {
      "mode": "DISABLED"
    }
  },
  "messages": [
    {
      "role": "system",
      "text": "You are a smart assistant."
    },
    {
      "role": "user",
      "text": "Name any three groups of grocery store products. For each group, give three subgroups. Present the result as a JSON object, where each group of products is represented by a key in the JSON object, and arrays from the relevant subgroups are the values. No introductory phrases or explanations needed, just data. Do not use Markdown."
    }
  ]
}

Result:

{
  "result": {
    "alternatives": [
      {
        "message": {
          "role": "assistant",
          "text": "{\n    \"meat\": [\"beef\", \"pork\", \"mutton\"],\n    \"dairy products\": [\"milk\", \"curd\", \"sour cream\"],\n    \"fruit\": [\"apples\", \"bananas\", \"oranges\"]\n}"
        },
        "status": "ALTERNATIVE_STATUS_FINAL"
      }
    ],
    "usage": {
      "inputTextTokens": "87",
      "completionTokens": "58",
      "totalTokens": "145"
    },
    "modelVersion": "07.03.2024"
  }
}

The model returned a response in JSON format with line breaks replaced with \n and quotation marks escaped.

If you do not get the result you expect using the prompt, try fine-tuning the model.

API parameters for saving the response structureAPI parameters for saving the response structure

For some text generation models, you can set the response format not only via a prompt but also using request parameters. For example, you can use the response formatting options to request a response in JSON format. There are two options to choose from:

  1. JSON with any structure:

    SDK
    API
    #!/usr/bin/env python3
    
    from __future__ import annotations
    
    import json
    
    import pydantic
    
    from yandex_cloud_ml_sdk import YCloudML
    
    text = """
    Name any three groups of grocery store products. 
    For each group, give three subgroups. 
    Present the result in JSON format.
    """
    
    
    def main() -> None:
        sdk = YCloudML(
            folder_id="<folder_ID>",
            auth="<API_key>",
        )
    
        model = sdk.models.completions("yandexgpt", model_version="rc")
    
        model = model.configure(response_format="json")
        result = model.run(
            [
                {"role": "user", "text": text},
            ]
        )
        print("JSON result:", result[0].text)
    
    
    if __name__ == "__main__":
        main()
    
    {
      "modelUri": "gpt://<folder_ID>/yandexgpt/rc",
      "completionOptions": {
        "stream": false
      },
      "messages": [
        {
          "role": "user",
          "text": "Name any three groups of grocery store products. For each group, give three subgroups. Present the result in JSON format."
        }
      ],
      "json_object": true
    }
    

    Tip

    If you want to get a JSON with an arbitrary structure, explicitly mention this in your prompt. Otherwise, the model may add extra brackets, spaces, indents and generate excessive tokens.

  2. JSON strictly following the specified schema:

    SDK
    API
    #!/usr/bin/env python3
    
    from __future__ import annotations
    
    import json
    
    import pydantic
    
    from yandex_cloud_ml_sdk import YCloudML
    
    text = "Name the date of Gagarin's first flight."
    
    
    def main() -> None:
        sdk = YCloudML(
            folder_id="<folder_ID>",
            auth="<API_key>",
        )
    
        model = sdk.models.completions("yandexgpt", model_version="rc")
    
        model = model.configure(
            response_format={
                "json_schema": {
                    "properties": {
                        "day": {
                            "title": "Day",
                            "description": "Day of the month",
                            "type": "integer",
                        },
                        "month": {
                            "title": "Month",
                            "description": "Month, in a word",
                            "type": "string",
                        },
                        "year": {
                            "title": "Year",
                            "description": "Year",
                            "type": "integer",
                        },
                    },
                    "required": ["day", "month", "year"],
                    "type": "object",
                }
            }
        )
        result = model.run(
            [
                {"role": "user", "text": text},
            ]
        )
        print("JSON result:", result[0].text)
    
    
    if __name__ == "__main__":
        main()
    
    {
      "modelUri": "gpt://<folder_ID>/yandexgpt/rc",
      "completionOptions": {
        "stream": false
      },
      "messages": [
        {
          "role": "user",
          "text": "Name the date of Gagarin's first flight."
        }
      ],
      "json_schema": {
        "schema": {
          "properties": {
            "day": {
              "title": "Day",
              "description": "Day of the month",
              "type": "integer"
            },
            "month": {
              "title": "Month",
              "description": "Month, in a word",
              "type": "string"
            },
            "year": {
              "title": "Year",
              "description": "Year",
              "type": "integer"
            }
          },
          "required": [
            "day",
            "month",
            "year"
          ],
          "type": "object"
        }
      }
    }
    

A strict response structure is required when working with external tools using function calls.

Was the article helpful?

Previous
Reasoning mode
Next
Supported classification types
© 2025 Direct Cursus Technology L.L.C.