Parameter Constraints
Parameter constraints limit the values passed to operations, preventing cost overruns, security issues, and compliance violations. This reference covers all constraint types.
Basic Structure
Parameter constraints are nested under constraints.parameters:
{
"constraints": {
"parameters": {
"operation-pattern": {
"parameter_name": constraint_specification
}
}
}
}Type Validation
Ensure parameters match expected types:
{
"constraints": {
"parameters": {
"llm:openai/chat.completions": {
"max_tokens": {"type": "integer"},
"temperature": {"type": "number"},
"model": {"type": "string"},
"stream": {"type": "boolean"},
"messages": {"type": "array"}
}
}
}
}| Type | Description | Examples |
|---|---|---|
| integer | Whole numbers | 1, 2, 100, -5 |
| number | Integers or floats | 1, 1.5, 3.14, -0.5 |
| string | Text values | "gpt-4", "hello" |
| boolean | True or false | true, false |
| array | Lists | [1, 2, 3], ["a", "b"] |
| object | Dictionaries | {"key": "value"} |
Numeric Constraints
Control numeric ranges with min,max, or range:
{
"constraints": {
"parameters": {
"llm:openai/chat.completions": {
"max_tokens": {
"type": "integer",
"min": 1,
"max": 4000
},
"temperature": {
"type": "number",
"range": [0.0, 2.0]
}
},
"finance:transfer": {
"amount": {
"type": "number",
"min": 0,
"max": 1000000
}
}
}
}
}minMinimum value (inclusive)
maxMaximum value (inclusive)
rangeArray [min, max] (shorthand)
Note: Use either min/max OR range, not both.
String Constraints
Control string values with enumerations, patterns, and length limits:
{
"constraints": {
"parameters": {
"llm:openai/chat.completions": {
"model": {
"type": "string",
"allowed_values": ["gpt-3.5-turbo", "gpt-4"]
}
},
"report:generate": {
"format": {
"type": "string",
"allowed_values": ["PDF", "XLSX", "CSV"]
},
"time_period": {
"type": "string",
"pattern": "^(Q[1-4]|H[1-2]|FY)\\d{4}$"
}
},
"user:create": {
"username": {
"type": "string",
"min_length": 3,
"max_length": 32,
"pattern": "^[a-zA-Z0-9_]+$"
}
}
}
}
}| Constraint | Description | Use Case |
|---|---|---|
| allowed_values | Array of permitted strings | Model selection, format types |
| pattern | Regex (must match entire string) | Date formats, identifiers |
| min_length | Minimum string length | Usernames, passwords |
| max_length | Maximum string length | Prevent injection, buffer overflow |
Array Constraints
Control array sizes to prevent resource exhaustion:
{
"constraints": {
"parameters": {
"llm:openai/chat.completions": {
"messages": {
"type": "array",
"min_items": 1,
"max_items": 100
}
},
"database:batch_insert": {
"records": {
"type": "array",
"max_items": 1000
}
}
}
}
}min_itemsMinimum array length (ensure at least N items)
max_itemsMaximum array length (prevent resource exhaustion)
Shorthand Formats
For convenience, MAPL supports shorthand formats:
"model": ["gpt-3.5-turbo", "gpt-4"]
"max_tokens": {"max": 500}"model": {"allowed_values": ["gpt-3.5-turbo", "gpt-4"]}
"max_tokens": {"type": "integer", "max": 500}Denied Parameters (Injection Defense)
Block dangerous parameter patterns with denied_parameters:
{
"constraints": {
"denied_parameters": {
"llm:**": {
"prompt": [
"*DROP TABLE*",
"*rm -rf*",
"*eval(*",
"*exec(*"
]
},
"tool:shell/*": {
"command": [
"*sudo*",
"*rm -*",
"*dd if=*"
]
}
}
}
}Important: Uses Wildcard Patterns, NOT Regex!
- •
*matches any characters (including spaces, /, :, special chars) - • Patterns are case-sensitive:
*DROP TABLE*≠*drop table* - • Use wildcards to match substrings:
*DROP TABLE*matches "foo DROP TABLE bar"
How Constraints Merge
When policies inherit, constraints merge using "most restrictive wins":
Company Policy:
max_tokens: [------------ 0 to 4000 ------------]
BU Analytics:
max_tokens: [------ 0 to 2000 ------]
User Alice:
max_tokens: [-- 0 to 500 --]
Final Result:
max_tokens: [-- 0 to 500 --] ← Most restrictive winsCompany Policy:
model: [gpt-3.5-turbo, gpt-4, gpt-4-turbo]
BU Analytics:
model: [gpt-3.5-turbo, gpt-4]
User Alice:
model: [gpt-3.5-turbo]
Final Result:
model: [gpt-3.5-turbo] ← IntersectionComplete Example
{
"constraints": {
"rate_limit": 50,
"parameters": {
"llm:openai/chat.completions": {
"model": {
"type": "string",
"allowed_values": ["gpt-3.5-turbo", "gpt-4"]
},
"max_tokens": {
"type": "integer",
"min": 1,
"max": 4000
},
"temperature": {
"type": "number",
"range": [0.0, 2.0]
},
"messages": {
"type": "array",
"min_items": 1,
"max_items": 100
}
},
"tool:database/query": {
"limit": {"type": "integer", "max": 1000},
"tables": {
"allowed_values": ["users", "orders", "products"]
}
}
},
"denied_parameters": {
"llm:**": {
"prompt": ["*DROP*", "*DELETE*", "*sudo*"]
}
}
}
}