Parameters

View as MarkdownOpen in Claude

Parameters

Define function parameters using JSON Schema to specify what arguments your functions accept. The AI extracts these from the conversation.

Parameter Structure

Parameters use JSON Schema format:

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

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

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 SwaigFunctionResult(
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 SwaigFunctionResult(
14 "Please provide the last 4 digits of your card."
15 )
16
17 # Process payment
18 return SwaigFunctionResult(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