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

# ASR biasing from functions

> Set and clear speech recognition biasing at runtime using conv.set_asr_biasing() for dynamic vocabulary.

<Info>
  **This page requires Python familiarity.** It covers dynamic ASR biasing from Python functions. For no-code ASR biasing in the flow editor, see [ASR biasing in flows](/flows/asr-biasing).
</Info>

Use dynamic ASR biasing when you need to bias speech recognition toward values retrieved at runtime – names from a CRM lookup, product codes from an API, or locations specific to the caller's account. Static biasing (configured in the flow editor or Speech Recognition page) cannot handle these cases.

Set and clear biasing using:

* `conv.set_asr_biasing()` – add keywords and custom biases
* `conv.clear_asr_biasing()` – remove previously set biasing

## How it behaves

### Persists across turns

ASR biasing set with `conv.set_asr_biasing()` stays active across turns. It will continue to apply until you:

* call `conv.clear_asr_biasing()`, or
* call `conv.set_asr_biasing()` again with new values.

You do not need to re-apply biasing on every turn.

### Takes priority over other ASR settings

Function-set ASR biasing has the highest priority. It is merged with any ASR configuration defined elsewhere, including:

* global ASR settings (configured on the **Channels > Voice > Speech recognition** page)
* step-level ASR settings (configured on individual flow steps)
* language-specific ASR settings

If the same phrase appears in multiple places, the value set by this type of biasing takes precedence.

<Note>
  ASR biasing cannot be configured at the flow level. To apply biasing across all steps in a flow, either use global biasing (applies everywhere) or set per-step biasing on each step within the flow. For runtime/dynamic biasing that persists across turns, use `conv.set_asr_biasing()` as described on this page.
</Note>

## When to use this

Use ASR biasing from functions when:

* You retrieve data at runtime and want ASR to reliably capture it.
* You are about to ask the user to say something you already know, such as a reference number or surname.
* Certain domain terms are often misheard and need extra support.

Sets ASR biasing for the current conversation.

### Parameters

#### keywords (optional, list of strings)

A list of phrases that are all biased equally. Use this when you have a small set of expected words and do not need different strengths.

#### custom\_biases (optional, dictionary mapping strings to numbers)

A mapping of phrase to bias weight. Use this when some phrases should be recognized more strongly than others.

### Validation

Inputs are validated when the function runs:

* `keywords` must be a list of strings
* `custom_biases` must be a dictionary with string keys and numeric values

Invalid inputs raise a `ValueError`.

## Examples

### Bias equally toward a set of terms

Use this when all phrases are equally important.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def set_expected_terms(conv):
    conv.set_asr_biasing(
        keywords=["hotel", "restaurant", "booking", "cancellation"]
    )
```

### Bias unevenly using custom weights

Use this when some phrases matter more than others.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def set_weighted_terms(conv):
    conv.set_asr_biasing(
        custom_biases={
            "booking reference": 3.0,
            "cancellation": 2.5,
            "non refundable": 2.0,
        }
    )
```

### Combine keywords and custom biases

This is common when you want a general nudge plus one high-priority term:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def set_mixed_biasing(conv):
    conv.set_asr_biasing(
        keywords=["dermatology", "eczema", "psoriasis"],
        custom_biases={"isotretinoin": 3.0}
    )
```

### Bias toward values returned from an API

Set biasing after fetching data, before asking the user to say it.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def verify_booking(conv):
    booking = conv.api.reservations.get_booking()

    conv.set_asr_biasing(
        custom_biases={
            booking["surname"]: 3.0,
            booking["reference"]: 3.0,
        }
    )

    conv.say("Could you confirm the surname and booking reference?")
```

## conv.clear\_asr\_biasing()

Clears any ASR biasing that was previously set for future turns.

This is recommended when biasing is only needed for a short part of the conversation, such as a verification step.

### Example: set biasing, then clear it

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def verify_reference(conv):
    ref = conv.api.orders.get_expected_reference()

    conv.set_asr_biasing(custom_biases={ref: 3.0})
    conv.say("Please say your reference number.")

    conv.clear_asr_biasing()
```

## Related documentation

* [Flows: ASR biasing](/flows/asr-biasing)
