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

# Apply text replacements

> Configure and manage find/replace rules that rewrite spoken phrases in the final transcript

<iframe className="w-full aspect-video rounded-xl" src="https://www.youtube.com/embed/d6WKOaS9_Ts?start=230&end=289" title="Apply Text Replacements — walkthrough" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowFullScreen />

<Info>
  **Follow along with the runnable example.** This guide walks through the [Text replacements example](https://github.com/corticph/corti-examples/tree/main/sdk/typescript/applets/src/applets/text-replacements) in `corti-examples` — bootstrap your build from it or use it as reference.
</Info>

Replacements rewrite spoken phrases in the **final transcript** — for example `"BID"` → `"twice daily"`. They are supplied in the dictation configuration as a list of `{ find, replace }` rules and applied server-side as the last step before a `transcript` message is returned.

This guide shows how to configure replacements through the [Dictation Web Component](/sdk/dictation/overview) and manage a reusable rule set.

<Note>
  For how replacements behave — case-insensitive matching, ordering relative to command detection, the per-connection limit, and worked examples — see the [Replacement Rules](/stt/replacements) reference. This page focuses on wiring them into your app.
</Note>

***

## Configure replacements

Add a `replacements` array to your `dictationConfig`. Each rule is a `{ find, replace }` pair.

<Warning>
  `dictationConfig` is an object, so it must be set as a **JavaScript property** — not an HTML attribute. Setting it re-applies on the next connection; rebuild and reassign the config when your rule set changes.
</Warning>

Because replacements are applied to the final text only, they never appear in interim results, and no special client-side handling is needed to receive them — the substituted text arrives inside the normal `transcript` message's `data.text`.

***

## Manage a rule set

In real apps the rules are rarely hard-coded — they come from a catalog plus user-defined entries. Model each rule with a stable `id` so it can be edited, removed, or protected, then derive the config array from the active set.

```ts title="JavaScript" theme={null}
interface Replacement {
  id: string;
  find: string;
  replace: string;
  builtin?: boolean; // protect catalog entries from deletion
}

// A preloaded catalog of common medical abbreviations.
const CATALOG: Replacement[] = [
  { id: "qd",  find: "QD",  replace: "once daily",        builtin: true },
  { id: "bid", find: "BID", replace: "twice daily",       builtin: true },
  { id: "tid", find: "TID", replace: "three times daily", builtin: true },
  { id: "prn", find: "PRN", replace: "as needed",         builtin: true },
];

// Derive the config from the active rules.
function buildReplacementConfig(primaryLanguage: string, items: Replacement[]) {
  return {
    primaryLanguage,
    replacements: items.map(({ find, replace }) => ({ find, replace })),
  };
}
```

<Tip>
  Persist a user's rule set per **API client** (e.g. keyed by `clientId:tenant`) so their replacements follow them across sessions without leaking between tenants.
</Tip>

***

## Export and share a rule set

To move a rule set between environments or check it into source control, serialize it in the config shape so it round-trips cleanly:

```json title="corti-replacements.json" theme={null}
{
  "type": "config",
  "configuration": {
    "replacements": [
      { "find": "QD", "replace": "once daily" },
      { "find": "BID", "replace": "twice daily" }
    ]
  }
}
```

***

## Next steps

<CardGroup cols={2}>
  <Card title="Replacement Rules" icon="arrow-right-arrow-left" href="/stt/replacements">
    Matching semantics, limits, and worked examples for the replacements feature.
  </Card>

  <Card title="Keyterms" icon="spell-check" href="/stt/guides/dictation-keyterms">
    Boost recognition of domain vocabulary before it reaches the transcript.
  </Card>

  <Card title="Example code" icon="github" href="https://github.com/corticph/corti-examples/tree/main/sdk/typescript/applets/src/applets/text-replacements">
    The complete, runnable Text replacements example in `corti-examples`.
  </Card>
</CardGroup>

<Note>Please [contact us](mailto:help@corti.ai) for help or questions.</Note>
