execute

View as MarkdownOpen in Claude

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]

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.

The handler can return a FunctionResult, a dict with a "response" key, or a plain string. All formats are normalized to a FunctionResult dictionary.

Example

1from signalwire import SWAIGFunction
2from signalwire import FunctionResult
3
4def handle_lookup(args, raw_data):
5 account_id = args.get("account_id", "")
6 return FunctionResult(f"Account {account_id} is active.")
7
8func = SWAIGFunction(
9 name="lookup_account",
10 handler=handle_lookup,
11 description="Look up account status",
12 parameters={
13 "type": "object",
14 "properties": {
15 "account_id": {"type": "string", "description": "Account ID"}
16 },
17 "required": ["account_id"]
18 }
19)
20
21result = func.execute({"account_id": "12345"}, raw_data={})
22print(result)
23# {"response": "Account 12345 is active."}