> This page is for Model APIs.

> Sarvam Voice Agents (Samvaad) is a voice AI agent platform for Indian languages: build, test and deploy AI calling agents on your own phone numbers, from ₹3 a minute. Start here: https://docs.sarvam.ai/voice-agents/why-voice-agents.
> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt. For a section index, append `/llms.txt` to any section URL (for example https://docs.sarvam.ai/voice-agents/llms.txt).
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Get JSON, Summaries and Answers

> Use output_rules to turn the whole recording into JSON for a form or CRM, a summary, answers to set questions, or a reply draft.

`output_rules` asks for one new text made from the whole recording. You get it in `output.text`, next to
the normal `text`. The output can only use what was said, and it sees the finished `text`, so a name that
your `vocabulary` fixed has the same spelling in `output`.

## A sales call into a CRM record

Describe every key: its type, what it holds, and what to write when it was not said.

#### Python

```python
import json, os
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])

CRM = """Return only one JSON object with exactly these keys, and
no other text. Use null for a value that was not said.
{
  "buyer_name": string | null,    // full name, in English letters
  "buyer_city": string | null,    // city, in English
  "buyer_phone": string | null,   // phone number, digits only
  "product": string | null,       // what the buyer wants, with size
  "quantity": number | null,      // how many units
  "unit_price_inr": number | null // price of one unit, in rupees
}"""

with open("sales_call.wav", "rb") as f:
    res = client.dictate.transcribe(file=f, language_code="hi-IN", output_rules=CRM)

record = json.loads(res.output.text)  # output.text is a string: parse it
print(json.dumps(record, indent=2, ensure_ascii=False))
total = record["quantity"] * record["unit_price_inr"]
print("order total (computed in code): ₹", total)
```

#### JavaScript

```javascript
import fs from "fs";
import { SarvamAIClient } from "sarvamai";

const client = new SarvamAIClient({ apiSubscriptionKey: process.env.SARVAM_API_KEY });

const CRM = `Return only one JSON object with exactly these keys, and
no other text. Use null for a value that was not said.
{
  "buyer_name": string | null,    // full name, in English letters
  "buyer_city": string | null,    // city, in English
  "buyer_phone": string | null,   // phone number, digits only
  "product": string | null,       // what the buyer wants, with size
  "quantity": number | null,      // how many units
  "unit_price_inr": number | null // price of one unit, in rupees
}`;

const res = await client.dictate.transcribe({
  file: fs.createReadStream("sales_call.wav"),
  language_code: "hi-IN",
  output_rules: CRM,
});

const record = JSON.parse(res.output.text); // output.text is a string: parse it
console.log(JSON.stringify(record, null, 2));
const total = record.quantity * record.unit_price_inr;
console.log("order total (computed in code): ₹", total);
```

**`Output`**

```text title="Output" wordWrap
{
  "buyer_name": "Sunita Kulkarni",
  "buyer_city": "Nashik",
  "buyer_phone": "9822041735",
  "product": "water tanks of 1000 liters",
  "quantity": 40,
  "unit_price_inr": 6800
}
order total (computed in code): ₹ 272000
```

## Answers to set questions

Give a way out for questions the call does not answer:

**`output_rules for questions`**

```python title="output_rules for questions"
QUESTIONS = """Answer each question on its own numbered line, in
English, in one short sentence. If the call does not answer a
question, write "Not mentioned".
1. Which city is the buyer from?
2. How many tanks does the buyer want?
3. Did the buyer ask for a discount?"""
```

Pass it as `output_rules` the same way, and print `res.output.text`.

## Write rules that work

| Do                                                                                                      | Why                                                                  |
| ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| Describe every key: type (`string \| null`, `number \| null`), what it holds                            | A bare JSON shape gets keys wrong more often                         |
| Say what to write when a value was not said (`null`, "Not mentioned")                                   | Otherwise the model may invent a value                               |
| For Indian-language audio, write "Write every value in English" at the top, or "in English" in each key | With no language named, the values come back in the speaker's script |
| Name the language of a summary: "in English"                                                            | Otherwise it can follow the clip                                     |
| Ask for one output per request                                                                          | Several outputs in one request can mix up                            |
| Leave `output_rules` out when you do not want an output                                                 | An empty string, or only spaces, means no output                     |
| Do sums in your own code                                                                                | The model's sums are not reliable                                    |
| Parse `output.text` yourself, and check `output.degraded`                                               | It is a string, and it can fail on its own while `text` is fine      |

The output call can take up to 90 s on the live socket, so give it time. Over a [WebSocket](/api/api-guides-tutorials/dictate/how-to/live-dictation),
the output comes in an `output.final` message after the last turn.