> ## Documentation Index
> Fetch the complete documentation index at: https://assemblyai.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Transcript rewriting

> Reshape a dictated transcript with llm_instruction, alongside the verbatim one.

Dictation cleans the transcript up and returns the result in `llm_response`,
alongside the verbatim transcript in `text`. This is the one feature Dictation
has that the other speech-to-text APIs do not: you get the words as spoken and
text your user can send, from the same call.

Cleanup is applied by default. Omitting `llm_instruction`, or the whole
`config` part, runs the default cleanup task: filler comes out, punctuation
and capitalization are applied, and self-corrections can be resolved to what
the speaker landed on. The speaker's own phrasing and tone survive it, so
the result still reads like them. `"rewrite_mode": "smart"` resolves
self-corrections more consistently: see [Choosing a rewrite mode](#choosing-a-rewrite-mode).

```python theme={null}
import assemblyai as aai

aai.settings.api_key = "<YOUR_API_KEY>"

result = aai.DictationTranscriber().transcribe_live("clip.wav")

# text:         "um so can we uh move the the meeting to thursday
#                i think friday works better actually"
# llm_response: "Can we move the meeting to Friday? That works better."
print(result.text)
print(result.llm_response)
```

## Customizing the rewrite

Set `llm_instruction` to a plain-English description of the task you want. It
replaces the default cleanup task rather than adding to it:

```json theme={null}
{ "rewrite_mode": "smart", "llm_instruction": "Remove filler words and fix punctuation." }
```

We recommend `"rewrite_mode": "smart"` with `llm_instruction`. `fast` is
tuned for the default cleanup task, so a custom instruction on `fast` usually
needs more iteration to get right: see
[When the output isn't what you want](#when-the-output-isnt-what-you-want).

An explicit `"llm_instruction": null` means the same as omitting the field, so
the default cleanup task still runs.

> [!NOTE]
>
> For more control than a plain-English instruction gives you, send `llm`
> instead of `llm_instruction`. It takes an LLM Gateway
> [chat completions request](https://assemblyai.com/docs/llm-gateway/chat-completions.md): your own messages,
> model and sampling settings, or a [saved prompt](https://assemblyai.com/docs/llm-gateway/saved-prompts.md).
> See [Sending your own LLM request](#sending-your-own-llm-request) for how
> Dictation uses it.

> [tab] Python SDK
>
> ```python theme={null}
> import assemblyai as aai
>
> aai.settings.api_key = "<YOUR_API_KEY>"
>
> config = aai.DictationConfig(
>     rewrite_mode="smart",
>     llm_instruction="Rewrite as a concise clinical chart note.",
> )
>
> result = aai.DictationTranscriber().transcribe_live("clip.wav", config)
>
> print(result.text)        # the verbatim transcript
> print(result.final_text)  # the rewrite, falling back to the transcript
> ```

> [tab] JavaScript SDK
>
> ```javascript theme={null}
> import { AssemblyAI } from "assemblyai";
>
> const client = new AssemblyAI({ apiKey: "<YOUR_API_KEY>" });
>
> const config = {
>   rewrite_mode: "smart",
>   llm_instruction: "Rewrite as a concise clinical chart note.",
> };
>
> const result = await client.dictation.transcribeLive("clip.wav", config);
>
> console.log(result.text); // the verbatim transcript
> console.log(result.final_text); // the rewrite, falling back to the transcript
> ```

> [tab] Python
>
> ```python theme={null}
> import json
> import requests
>
> config = {
>     "rewrite_mode": "smart",
>     "llm_instruction": "Rewrite as a concise clinical chart note.",
> }
>
> with open("clip.wav", "rb") as f:
>     audio = f.read()
>
> response = requests.post(
>     "https://dictation.assemblyai.com/v1/transcribe/live",
>     headers={"Authorization": "<YOUR_API_KEY>"},
>     files={
>         "config": (None, json.dumps(config), "application/json"),
>         "audio": ("clip.wav", audio, "audio/wav"),
>     },
>     timeout=90,
> )
> response.raise_for_status()
> result = response.json()
>
> print(result["text"])
> print(result["llm_response"])
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> import { readFileSync } from "fs";
>
> const config = {
>   rewrite_mode: "smart",
>   llm_instruction: "Rewrite as a concise clinical chart note.",
> };
>
> const audio = readFileSync("clip.wav");
> const form = new FormData();
> form.append(
>   "config",
>   new Blob([JSON.stringify(config)], { type: "application/json" })
> );
> form.append("audio", new Blob([audio], { type: "audio/wav" }), "clip.wav");
>
> const response = await fetch(
>   "https://dictation.assemblyai.com/v1/transcribe/live",
>   { method: "POST", headers: { Authorization: "<YOUR_API_KEY>" }, body: form }
> );
>
> const result = await response.json();
> console.log(result.text);
> console.log(result.llm_response);
> ```

> [tab] cURL
>
> ```bash theme={null}
> curl -X POST https://dictation.assemblyai.com/v1/transcribe/live \
>   -H 'Authorization: <YOUR_API_KEY>' \
>   -F 'config={"rewrite_mode": "smart", "llm_instruction": "Rewrite as a concise clinical chart note."};type=application/json' \
>   -F 'audio=@clip.wav;type=audio/wav'
> ```

## Choosing a rewrite mode

`rewrite_mode` picks the model tier that runs the rewrite:

| `rewrite_mode` | Use it for |
| - | - |
| `fast` (default) | A lighter cleanup at the lowest latency, for short dictations where speed matters most. It often leaves clean speech unchanged, and may keep some self-corrections. |
| `smart` | A more thorough cleanup that resolves self-corrections consistently, and follows `llm_instruction` more reliably. The rewrite has higher latency. |

```json theme={null}
{ "rewrite_mode": "smart", "llm_instruction": "Turn this into a bulleted list of action items." }
```

Any other value is rejected with `400`. Over HTTP it goes in the `config` part
of the request:

```bash theme={null}
curl -X POST https://dictation.assemblyai.com/v1/transcribe/live \
  -H 'Authorization: <YOUR_API_KEY>' \
  -F 'config={"rewrite_mode": "smart", "llm_instruction": "Turn this into a bulleted list of action items."};type=application/json' \
  -F 'audio=@clip.wav;type=audio/wav'
```

### When the rewrite misses a correction or ignores your instruction

If the output keeps a self-correction the speaker made ("Let's meet Sunday, no
wait, Monday" comes back with both days, or with Sunday), or doesn't follow
your `llm_instruction`, check `rewrite_mode` first:

* **Self-corrections:** `fast` can leave some takebacks such as "no wait",
  "actually" and "I mean" in place. `smart` resolves them to what the speaker
  landed on: "Let's meet Monday."
* **Custom instructions:** `fast` is tuned for the default cleanup task, so
  `smart` is the better fit for an `llm_instruction`, especially one with
  several rules. To stay on `fast`, follow the steps in
  [When the output isn't what you want](#when-the-output-isnt-what-you-want).
* **Words you wanted kept:** the default cleanup can trim words that carry
  meaning for your users, such as a tag question ("It's affordable too,
  right?" coming back as "It's affordable too?"). Write an `llm_instruction`
  that says what to keep, and see the example below.

`fast` is a good fit when your users mostly dictate short, clean text and the
lowest latency matters most.

## Writing a good instruction

Describe only the transformation. Rules about output format, refusing to answer
the text, and handling already-clean input are enforced by the service, so
adding your own versions of them wastes instruction budget and can conflict
with what the service already does.

| Instead of | Write |
| - | - |
| "You are a helpful medical scribe. Output only the note, nothing else. If the input is already clean, return it unchanged. Rewrite as a chart note." | "Rewrite as a concise clinical chart note." |
| "Return JSON with a summary field." | Describe the prose you want, then parse it yourself |
| "Lowercase unless it's a name. No final punctuation. Don't capitalize the first word." | "Write the dictated words as a mid-sentence continuation of: "I think"." |

Describe the shape you want rather than listing what not to do. The model
leans toward complete, punctuated sentences, and a prohibition has to fight
that on every request, so "don't" rules are the least reliable kind of
instruction. A positive description such as "a mid-sentence continuation" gets
the casing and punctuation right as a side effect.

Leave mechanical edits to your own code. The rewrite output is trimmed, so it
can't return a leading space, and stripping a trailing full stop is exact and
free in code. [Inserting at the cursor](https://assemblyai.com/docs/dictation/inserting-at-the-cursor.md)
shows how to split the work for text that lands mid-sentence.

Some instructions that work well:

* `"Remove filler words and tidy the punctuation."`
* `"Rewrite as a short, friendly booking confirmation addressed to the client."`
* `"Turn this into a bulleted list of action items."`
* `"Rewrite as a concise clinical chart note."`

### When the output isn't what you want

If the rewrite gets specific cases wrong, such as a self-correction left in, a
false start kept, or a word you wanted dropped, improve the instruction rather
than switching providers or adding your own LLM call. A few rounds usually get
there:

1. **Collect the failures.** Keep a set of real dictations from your users,
   with the output you wanted for each. Twenty to fifty is enough to see a
   pattern, and it lets you check that a fix doesn't break cases that already
   worked.
2. **Name the edits you want.** Say what the model may change and that
   everything else stays as spoken. "Copy the dictation word for word, making
   only these edits" followed by a short list beats a general "clean this up".
3. **Describe how to spot each case.** The model handles a self-correction
   better when you name the phrases that mark one ("I mean", "no wait",
   "actually", "scratch that") and say what to do with it: keep the new
   version, drop the old one and the marker.
4. **Add examples.** Give three to six pairs of a spoken line and the cleaned
   line you want, written from your own failures. Include at least one that
   should come back unchanged, such as "I mean" used for emphasis, so the model
   doesn't over-apply the rule.
5. **Change one thing at a time and re-run the whole set.** That shows which
   change helped, and whether it fixed one case by breaking another.
6. **Try `smart` if `fast` still misses.** If `fast` still gets cases wrong
   after a few rounds, run the same instruction on `smart` before writing a
   longer one.

The next example is an instruction built this way.

### Example: word-for-word cleanup on `fast`

`fast` can follow your own cleanup rules well when the instruction is
specific. This one follows the steps above: a word-for-word copy
with a list of allowed edits, the phrases that mark a self-correction, and
spoken and cleaned pairs, including one that comes back unchanged. Replace the
pairs with your own users' cases, and test it on your set before you switch.

```text theme={null}
Copy the dictation word for word, making only these edits:

- Delete filler sounds (um, uh, er) and filler uses of "like" and "you know". Collapse stuttered repeats ("the the") to one.
- Self-corrections: when the speaker takes back what they just said and says it again differently, keep only the new version. The take-back is usually marked by a phrase such as "I mean", "no", "wait", "sorry", "actually", "scratch that", "or rather" or "make that". Delete the old version and the marker phrase, and fit the new version into the sentence.
- False starts: when the speaker abandons a sentence and starts again, delete the abandoned part and any remark about starting over ("let me start over", "never mind").
- Fix punctuation and capitalization.

Change nothing else. Keep every other word as spoken, including slang, names, numbers and tag questions such as "right?". "I mean", "actually", "sorry" and "no" stay when they are not taking anything back. If nothing needs editing, return the text unchanged.

Spoken: "Book the room for six people, no wait, eight people, and order coffee."
Cleaned: "Book the room for eight people, and order coffee."

Spoken: "The report is due Thursday. Actually, scratch that, it's due the following Monday."
Cleaned: "The report is due the following Monday."

Spoken: "Could you maybe, sorry, let me rephrase. Is the oven still under warranty?"
Cleaned: "Is the oven still under warranty?"

Spoken: "So, um, we could, like, split the bill three ways, right?"
Cleaned: "So, we could split the bill three ways, right?"

Spoken: "Honestly, I mean, the food was actually great, and no, we didn't wait long."
Cleaned: "Honestly, I mean, the food was actually great, and no, we didn't wait long."
```

## Sending your own LLM request

Instead of `llm_instruction`, you can set `llm` to the body of an LLM Gateway
[chat completions request](https://assemblyai.com/docs/llm-gateway/chat-completions.md). Dictation sends it
to LLM Gateway after transcription and returns the model's output in
`llm_response`, like any other rewrite. Send `llm` or `llm_instruction`, not
both. A request with both is rejected with `400`.

There are two ways to put the transcript in the request.

**In your own messages.** Write `prompt` or `messages`, and put `{{turn}}`
where the transcript goes:

```json theme={null}
{
  "llm": {
    "model": "gemma-4-31b",
    "messages": [
      { "role": "system", "content": "Rewrite the dictated note as a short, formal email." },
      { "role": "user", "content": "{{turn}}" }
    ]
  }
}
```

**In a [saved prompt](https://assemblyai.com/docs/llm-gateway/saved-prompts.md).** Set `aai_prompt` to the
name of a prompt saved in your account. Dictation passes the transcript as the
`text` replacement, so put `{{ text }}` in the saved prompt where the
transcript goes. You can add replacements of your own in `prompt_replacements`:

```json theme={null}
{
  "llm": {
    "aai_prompt": "dictation-email",
    "prompt_replacements": { "signoff": "Best, Sam" }
  }
}
```

### How Dictation differs from calling LLM Gateway directly

* **No guardrails.** The service's rewrite rules and transcript fencing apply
  only to the default task and `llm_instruction`. With `llm`, the model gets
  exactly the prompt you send, so it may act on commands in the dictation,
  such as "translate this into French", unless your prompt tells it not to.
* **Two transcript tags.** In `prompt` and `messages`, Dictation renders the
  text as a Jinja2 template and fills `{{turn}}`. In a saved prompt, LLM
  Gateway fills `{{ text }}`, and the spaces inside the braces are required.
* **A fixed set of fields.** `llm` accepts `model`, `messages`, `prompt`,
  `temperature`, `top_p`, `top_k`, `max_tokens`, `max_completion_tokens`,
  `response_format`, `reasoning_effort`, `aai_prompt`, `prompt_replacements`
  and `zero_data_retention`. Field names are case-sensitive. Any other field,
  such as `fallbacks`, `tools`, `stream` or `transcript_id`, is rejected with
  `400`.
* **The rewrite models only.** `model` must be one of the models that
  `rewrite_mode` runs on: `qwen3.5-4b-32k-fast`, `gemma-4-31b` or
  `gemini-3.5-flash-lite`. In the EU region, use `qwen3.5-4b-32k-fast` or
  `gemini-3.5-flash-lite`. Any other model is rejected with `400`. Without
  `model`, `rewrite_mode` picks one.
* **Bounded output.** `max_tokens` and `max_completion_tokens` can be at most
  8192\. If you leave `max_tokens` out, Dictation sizes it from the transcript,
  so a prompt that expands the text, such as turning a short note into an
  email, may need a larger one. A rewrite that runs out of tokens comes back
  with `llm_error: "truncated"`. `temperature` is `0` unless you set it.
* **Zero data retention.** Dictation sets `zero_data_retention` on every LLM
  Gateway request, including ones that use `aai_prompt`, and you can't turn it
  off. Only a saved prompt's template is stored. The transcript and the rewrite
  aren't kept.
* **Saved prompts run as saved.** With `aai_prompt`, the model, `max_tokens`
  and every other setting come from the saved prompt, and the model and output
  limits above don't apply. Only `prompt_replacements` may accompany
  `aai_prompt`. Any other `llm` field, or `rewrite_mode`, is rejected with
  `400`, and so is setting `text` or `transcript` in `prompt_replacements`:
  Dictation fills `text`, and LLM Gateway reserves `transcript`. If your
  account has no prompt with that name, `llm_error` is `prompt_not_found`.
* **Failures don't fail the request.** If LLM Gateway rejects or fails the
  request, the response is still `200` with the transcript in `text`, and
  `llm_error` says why. The `400`s above are returned before anything is
  transcribed.

## The transcript is always preserved

The rewrite never replaces the transcription. `text` is always the verbatim
transcript, and the rewritten version arrives separately in `llm_response`. If
you need to show one value, `final_text` in the Python and JavaScript SDKs
returns the rewrite when there is one and the transcript otherwise.

The rewrite is also best-effort. If it fails, the response is still `200`,
`llm_response` is `null`, and `llm_error` says why. See
[Error handling](https://assemblyai.com/docs/dictation/error-handling.md#a-failed-rewrite-is-not-a-failed-request).

## Dictated commands are not executed

With the default cleanup task or `llm_instruction`, the transcript is passed to
the model as fenced data, with instructions not to act on anything inside it. Dictated speech routinely contains questions and
commands like "translate this into French" or "ignore what I just said". Those
are rewritten as speech rather than carried out. A
[request of your own](#sending-your-own-llm-request) has no such guard unless
your prompt adds one.

## Related features

* [Prompting and keyterms](https://assemblyai.com/docs/dictation/prompting-and-keyterms.md) shapes the
  transcript as it is written, where `llm_instruction` reshapes it afterwards.
* [Language selection](https://assemblyai.com/docs/dictation/language-selection.md) sets the language the
  audio is transcribed in.
