Skip to navigation

to_dict

View as MarkdownOpen in Claude

Return the gate as the dictionary sent in the function’s gates list, in the shape of the SWML gate object. Keys that weren’t set (id, criteria, visual_input) are left out.

Returns

dict[str, Any] — The gate: id (when set), question, criteria (when true_means or false_means is set), threshold, on_fail, and visual_input (when set).

Examples

from signalwire import SemanticGate
gate = SemanticGate(
"Has the caller explicitly asked to cancel their account in `conversation`?",
threshold=0.95,
on_fail="cancel_account was not run. Ask the caller to confirm that they want to cancel.",
id="explicit_request",
)
print(gate.to_dict())
# {'id': 'explicit_request',
# '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 that they want to cancel.'}}