{
"success": true,
"message": "success",
"data": {
"id": "9c1d2e3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f",
"projectId": "fbb9e8b2-2dbb-40f9-a051-9404624e3247",
"userId": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"createdBy": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"updatedBy": null,
"name": "has_card_number",
"notes": "Matches 13 to 19 digits in a row",
"type": "JAVASCRIPT_FUNCTION",
"usedAs": "CHECK",
"code": "return /\\d{13,19}/.test(text.replace(/[\\s-]/g, ''));",
"params": null,
"requiredParams": [
"name"
],
"createdAt": "2026-10-20T09:15:00.000Z",
"updatedAt": "2026-10-20T09:15:00.000Z"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}Create Function or Macro
Creates a JavaScript function or a Jinja macro. Guardrails use them as checks (CHECK, in lookFor) or actions (ACTION, in behaviour); prompts call HELPER macros by name, as {{ <name>(...) }}. The code is checked when you save it. A call gets only the agent’s active functions and macros: assign them with PUT /v2/voice-agents/{voiceAgentId}/functions-macros, or with functionMacroIds when you create a v2 agent (updating an agent does not change its assignments). Try code first with POST /v2/voice-agents/functions-macros/test.
{
"success": true,
"message": "success",
"data": {
"id": "9c1d2e3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f",
"projectId": "fbb9e8b2-2dbb-40f9-a051-9404624e3247",
"userId": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"createdBy": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"updatedBy": null,
"name": "has_card_number",
"notes": "Matches 13 to 19 digits in a row",
"type": "JAVASCRIPT_FUNCTION",
"usedAs": "CHECK",
"code": "return /\\d{13,19}/.test(text.replace(/[\\s-]/g, ''));",
"params": null,
"requiredParams": [
"name"
],
"createdAt": "2026-10-20T09:15:00.000Z",
"updatedAt": "2026-10-20T09:15:00.000Z"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}Authorizations
Body
Name (1-255 characters), unique in the project. A HELPER macro's name must be an identifier: letters, digits and underscores, not starting with a digit (FunctionMacroHelperNameInvalid), and its code must define {% macro <name>(...) %} with this name. For any macro written as definitions, the one named like the record runs (else the first).
1 - 255CHECK: answers "does this text match?" (a guardrail's lookFor). ACTION: answers "what changes?" (a guardrail's behaviour): new text, or variables to set. HELPER: a macro prompts call by its name, as {{ <name>(...) }} (JINJA_MACRO only).
CHECK, ACTION, HELPER The code (1-20,000 characters), compiled when you save it.
Function: the body of function (text, vars) { ... }. text is what was said, as said; vars are the call's variables, as text unless a value is JSON. A CHECK returns true to match. An ACTION returns a string (the new text) or an object (the variables to set). JavaScript built-ins only (no console, fetch or timers); 50 ms and 16 MiB per run.
Macro: a template with text, vars and args, or a {% macro <name>(...) %} definition (required for HELPER, named like the record). A CHECK matches unless it renders empty, false, 0, none or no. An ACTION sets variables when it renders a JSON object; anything else is the new text. 50 ms and 64 KiB of output.
1 - 20000HELPER macros only, and optional: the parameters that the {% macro <name>(...) %} in code declares, in order. Hamsa reads them from the code; if you send them they must match it (FunctionMacroParamsMismatch). Leave out or null for CHECK and ACTION.
2064^[A-Za-z_][A-Za-z0-9_]*$Was this page helpful?