> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# applyGateFields

> Check and normalize the gates and gate fillers in a function definition, in place.

[gate-definitions]: /docs/server-sdks/reference/typescript/agents/semantic-gate/gate-definitions

Check and normalize `gates` and `gate_fillers` in a function's fields, in place.
`fields` is a function definition or the extra fields of one. Its `gates` become
the plain objects the platform reads, as returned by
[`gateDefinitions()`][gate-definitions]. A `gate_fillers` that is left out or
`null` is removed, because the platform ignores it.

## Parameters

**`fields`** `Record<string, unknown>` — required

The function definition or its extra fields. Modified in place.

---

**`functionName`** `string` — required

The function's name, used in error messages and checked against the reserved
function names.

---

**`opts`** `{ definition?: boolean }`

Optional settings.

---

**`opts.definition`** `boolean` — default: false

Set to `true` when `fields` is a whole function definition sent as written, such
as a `DataMap`'s or a raw one. Then the `gates` and `gate_fillers` keys are found
without regard to case, `gates: null` is refused, and a gated function needs a
`description` (or `purpose`). When `false`, a `null` or `undefined` `gates` means
no gates, as an option left out does.

---

## Returns

`void`

Throws `Error` for gates the platform would refuse, for `gate_fillers` on a
function without gates (the platform ignores them there), for `gate_fillers` that
isn't an object mapping a language code, `'auto'`, or `'default'` to a list of
phrases, and, with `definition: true`, for a gated definition without a
description.

## Examples

```typescript {14}
import { applyGateFields } from '@signalwire/sdk';

const fields: Record<string, unknown> = {
  gates: [
    {
      question: 'Has the caller explicitly asked to cancel their account in `conversation`?',
      threshold: 0.95,
      on_fail: { response: 'cancel_account was not run. Ask the caller to confirm.' },
    },
  ],
  gate_fillers: { 'en-US': ['One moment.'] },
};

applyGateFields(fields, 'cancel_account');
console.log(fields.gates); // the gate as a plain object, deep-copied
```