Parameters

View as MarkdownOpen in Claude

Parameter Structure

Parameters use JSON Schema format. The schema is identical across all SDK languages — only the host-language syntax for expressing the object differs:

1parameters={
2 "type": "object",
3 "properties": {
4 "param_name": {
5 "type": "string", # Data type
6 "description": "Description" # Help AI understand the parameter
7 }
8 },
9 "required": ["param_name"] # Required parameters
10}

Parameter Definition Across Languages

LanguageSyntax for Parameters Object
Python{"type": "object", "properties": {"p": {"type": "string", "description": "d"}}, "required": ["p"]}
TypeScript{ type: 'object', properties: { p: { type: 'string', description: 'd' } }, required: ['p'] }

All parameter examples below use Python dict syntax. The JSON Schema structure is the same in every language — translate the dict/map syntax to your language as shown in the table above.

Parameter Types

TypeDescriptionExample Values
stringText values"hello", "12345", "New York"
numberNumeric values42, 3.14, -10
integerWhole numbers only1, 42, -5
booleanTrue/falsetrue, false
arrayList of values["a", "b", "c"]
objectNested structure{"key": "value"}

String Parameters

Basic string parameters:

1parameters={
2 "type": "object",
3 "properties": {
4 "name": {
5 "type": "string",
6 "description": "Customer name"
7 },
8 "email": {
9 "type": "string",
10 "description": "Email address"
11 },
12 "phone": {
13 "type": "string",
14 "description": "Phone number in any format"
15 }
16 },
17 "required": ["name"]
18}

Enum Parameters

Restrict to specific values:

1parameters={
2 "type": "object",
3 "properties": {
4 "department": {
5 "type": "string",
6 "description": "Department to transfer to",
7 "enum": ["sales", "support", "billing", "returns"]
8 },
9 "priority": {
10 "type": "string",
11 "description": "Issue priority level",
12 "enum": ["low", "medium", "high", "urgent"]
13 }
14 },
15 "required": ["department"]
16}

Number Parameters

1parameters={
2 "type": "object",
3 "properties": {
4 "quantity": {
5 "type": "integer",
6 "description": "Number of items to order"
7 },
8 "amount": {
9 "type": "number",
10 "description": "Dollar amount"
11 },
12 "rating": {
13 "type": "integer",
14 "description": "Rating from 1 to 5",
15 "minimum": 1,
16 "maximum": 5
17 }
18 },
19 "required": ["quantity"]
20}

Boolean Parameters

1parameters={
2 "type": "object",
3 "properties": {
4 "gift_wrap": {
5 "type": "boolean",
6 "description": "Whether to gift wrap the order"
7 },
8 "express_shipping": {
9 "type": "boolean",
10 "description": "Use express shipping"
11 }
12 }
13}

Array Parameters

1parameters={
2 "type": "object",
3 "properties": {
4 "items": {
5 "type": "array",
6 "description": "List of menu items to order",
7 "items": {
8 "type": "string"
9 }
10 },
11 "tags": {
12 "type": "array",
13 "description": "Tags to apply",
14 "items": {
15 "type": "string",
16 "enum": ["urgent", "vip", "callback"]
17 }
18 }
19 },
20 "required": ["items"]
21}

Object Parameters

1parameters={
2 "type": "object",
3 "properties": {
4 "address": {
5 "type": "object",
6 "description": "Delivery address",
7 "properties": {
8 "street": {"type": "string"},
9 "city": {"type": "string"},
10 "zip": {"type": "string"}
11 },
12 "required": ["street", "city", "zip"]
13 }
14 },
15 "required": ["address"]
16}

Optional vs Required Parameters

1parameters={
2 "type": "object",
3 "properties": {
4 # Required - AI must extract this
5 "order_number": {
6 "type": "string",
7 "description": "Order number (required)"
8 },
9 # Optional - AI will include if mentioned
10 "include_tracking": {
11 "type": "boolean",
12 "description": "Include tracking details"
13 },
14 # Optional with default handling
15 "format": {
16 "type": "string",
17 "description": "Output format",
18 "enum": ["brief", "detailed"],
19 "default": "brief"
20 }
21 },
22 "required": ["order_number"] # Only order_number is required
23}

Default Values

Handle missing optional parameters in your handler. The pattern for accessing arguments with defaults varies by language:

LanguageGet with Default
Pythonargs.get("key", "default")
TypeScriptargs.key ?? 'default' or args['key'] ?? 'default'
1def search_products(self, args, raw_data):
2 # Get required parameter
3 query = args.get("query")
4
5 # Get optional parameters with defaults
6 category = args.get("category", "all")
7 max_results = args.get("max_results", 5)
8 sort_by = args.get("sort_by", "relevance")
9
10 # Use parameters
11 results = self.db.search(
12 query=query,
13 category=category,
14 limit=max_results,
15 sort=sort_by
16 )
17
18 return FunctionResult(f"Found {len(results)} products")

Parameter Descriptions

Good descriptions help the AI extract parameters correctly:

1parameters={
2 "type": "object",
3 "properties": {
4 # Good - specific format guidance
5 "order_number": {
6 "type": "string",
7 "description": "Order number, usually starts with ORD- followed by digits"
8 },
9
10 # Good - examples help
11 "date": {
12 "type": "string",
13 "description": "Date in MM/DD/YYYY format, e.g., 12/25/2024"
14 },
15
16 # Good - clarifies ambiguity
17 "amount": {
18 "type": "number",
19 "description": "Dollar amount without currency symbol, e.g., 29.99"
20 },
21
22 # Bad - too vague
23 "info": {
24 "type": "string",
25 "description": "Information" # Don't do this
26 }
27 }
28}

Complex Example

1from signalwire import AgentBase, FunctionResult
2
3class TravelAgent(AgentBase):
4 def __init__(self):
5 super().__init__(name="travel-agent")
6 self.add_language("English", "en-US", "rime.spore")
7
8 self.define_tool(
9 name="search_flights",
10 description="Search for available flights between cities",
11 parameters={
12 "type": "object",
13 "properties": {
14 "from_city": {
15 "type": "string",
16 "description": "Departure city or airport code"
17 },
18 "to_city": {
19 "type": "string",
20 "description": "Destination city or airport code"
21 },
22 "departure_date": {
23 "type": "string",
24 "description": "Departure date in YYYY-MM-DD format"
25 },
26 "return_date": {
27 "type": "string",
28 "description": "Return date in YYYY-MM-DD format (optional for one-way)"
29 },
30 "passengers": {
31 "type": "integer",
32 "description": "Number of passengers",
33 "minimum": 1,
34 "maximum": 9
35 },
36 "cabin_class": {
37 "type": "string",
38 "description": "Preferred cabin class",
39 "enum": ["economy", "premium_economy", "business", "first"]
40 },
41 "preferences": {
42 "type": "object",
43 "description": "Travel preferences",
44 "properties": {
45 "nonstop_only": {
46 "type": "boolean",
47 "description": "Only show nonstop flights"
48 },
49 "flexible_dates": {
50 "type": "boolean",
51 "description": "Search nearby dates for better prices"
52 }
53 }
54 }
55 },
56 "required": ["from_city", "to_city", "departure_date"]
57 },
58 handler=self.search_flights
59 )
60
61 def search_flights(self, args, raw_data):
62 from_city = args.get("from_city")
63 to_city = args.get("to_city")
64 date = args.get("departure_date")
65 passengers = args.get("passengers", 1)
66 cabin = args.get("cabin_class", "economy")
67 prefs = args.get("preferences", {})
68
69 nonstop = prefs.get("nonstop_only", False)
70
71 # Your flight search logic here
72 return FunctionResult(
73 f"Found 3 flights from {from_city} to {to_city} on {date}. "
74 f"Cheapest: $299 {cabin} class"
75 )

Validating Parameters

Add validation in your handler:

1def process_payment(self, args, raw_data):
2 amount = args.get("amount")
3 card_last_four = args.get("card_last_four")
4
5 # Validate amount
6 if amount is None or amount <= 0:
7 return FunctionResult(
8 "Invalid amount. Please specify a positive dollar amount."
9 )
10
11 # Validate card
12 if not card_last_four or len(card_last_four) != 4:
13 return FunctionResult(
14 "Please provide the last 4 digits of your card."
15 )
16
17 # Process payment
18 return FunctionResult(f"Processing ${amount:.2f} on card ending {card_last_four}")

Parameter Best Practices

DO:

  • Use clear, descriptive names (order_number not num)
  • Provide detailed descriptions with examples
  • Use enum for fixed choices
  • Mark truly required parameters as required
  • Handle missing optional parameters with defaults

DON’T:

  • Require parameters the caller might not know
  • Use ambiguous descriptions
  • Expect perfect formatting (be flexible in handlers)
  • Create too many required parameters