Docs/Policies/Constraints

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"}
      }
    }
  }
}
TypeDescriptionExamples
integerWhole numbers1, 2, 100, -5
numberIntegers or floats1, 1.5, 3.14, -0.5
stringText values"gpt-4", "hello"
booleanTrue or falsetrue, false
arrayLists[1, 2, 3], ["a", "b"]
objectDictionaries{"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
        }
      }
    }
  }
}
min

Minimum value (inclusive)

max

Maximum value (inclusive)

range

Array [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_]+$"
        }
      }
    }
  }
}
ConstraintDescriptionUse Case
allowed_valuesArray of permitted stringsModel selection, format types
patternRegex (must match entire string)Date formats, identifiers
min_lengthMinimum string lengthUsernames, passwords
max_lengthMaximum string lengthPrevent 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_items

Minimum array length (ensure at least N items)

max_items

Maximum array length (prevent resource exhaustion)


Shorthand Formats

For convenience, MAPL supports shorthand formats:

Shorthand
"model": ["gpt-3.5-turbo", "gpt-4"]
"max_tokens": {"max": 500}
Equivalent Full Form
"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 wins
Company 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]  ← Intersection

Complete Example

Comprehensive constraints
{
  "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*"]
      }
    }
  }
}

Related Topics