> 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.

# execute

> Execute the function with the given arguments.

[ref-functionresult]: /docs/server-sdks/reference/python/agents/function-result

Execute the function with the given arguments. Calls the handler and normalizes
the return value into a FunctionResult dictionary.

## **Parameters**

**`args`** `dict[str, Any]` — required

Parsed arguments for the function, matching the parameter schema.

---

**`raw_data`** `dict[str, Any] | None` — default: None

Full raw request data including `global_data`, `call_id`, `caller_id_number`,
`meta_data`, and `ai_session_id`.

---

## **Returns**

`dict[str, Any]` -- The function result as a dictionary (from
`FunctionResult.to_dict()`). If the handler raises an exception, returns a
generic error message rather than exposing internal details.

> **Note**
>
> The handler can return a [`FunctionResult`][ref-functionresult], a `dict` with a `"response"` key,
> or a plain string. All formats are normalized to a FunctionResult dictionary.

## **Example**

```python {21}
from signalwire import SWAIGFunction
from signalwire import FunctionResult

def handle_lookup(args, raw_data):
    account_id = args.get("account_id", "")
    return FunctionResult(f"Account {account_id} is active.")

func = SWAIGFunction(
    name="lookup_account",
    handler=handle_lookup,
    description="Look up account status",
    parameters={
        "type": "object",
        "properties": {
            "account_id": {"type": "string", "description": "Account ID"}
        },
        "required": ["account_id"]
    }
)

result = func.execute({"account_id": "12345"}, raw_data={})
print(result)
# {"response": "Account 12345 is active."}
```