Screen an agent's environment request against the catalog
Your task
Developers wait days for environments, so an agent now requests them through a provisioning pipeline. The agent can touch the cloud account, so the pipeline screens every request against a catalog of approved settings, even when the agent was tricked into asking for more.
Write screen_provision_request(request_fields, team_active_envs): the check every request passes through.
request_fields(list of str): the request, askey=valuefields such as"size=medium".team_active_envs(int): how many environments the requesting team already runs.- Return
"approve","deny:<key>"(a line the agent may never cross),"escalate:<key>"(outside the defaults, so a platform engineer decides), or"deny:malformed".
The catalog keys, in catalog order, are size, region, ttl_hours (the environment's lifetime), budget_usd and network. Values are compared exactly, with no trimming or case changes. Check in this order and return at the first problem:
- Go through the fields in input order. Split each at its first
=. A field with no=:"deny:malformed". A key that is not a catalog key:"deny:<key>". A key already seen in this request:"deny:<key>". - The first catalog key, in catalog order, that the request does not include:
"escalate:<key>". sizeother thansmall,mediumorlarge:"escalate:size".regionother thanus-eastoreu-west:"escalate:region".ttl_hours: if it is not 1 to 9 digits (0 to 9 only), or it is 0:"deny:ttl_hours". Over 72:"escalate:ttl_hours".budget_usd: if it is not 1 to 9 digits (0 to 9 only), or it is 0:"deny:budget_usd". Over 500:"escalate:budget_usd".networkofprodorproduction:"deny:network". Any other value exceptdevorstaging:"escalate:network".team_active_envsof 5 or more:"escalate:team_active_envs".- Otherwise:
"approve".
Then, in a sentence or two: why deny an unknown key instead of ignoring it?
Examples
screen_provision_request(request_fields: list[str], team_active_envs: int) -> strExample 1
Input
screen_provision_request(["size=medium", "region=us-east", "ttl_hours=24", "budget_usd=200", "network=dev"], 2)Output
"approve"Example 2
Input
screen_provision_request(["size=small", "region=eu-west", "ttl_hours=8", "budget_usd=50", "network=prod"], 0)Output
"deny:network"Example 3
Input
screen_provision_request(["size=large", "region=us-east", "ttl_hours=48", "budget_usd=900", "network=staging"], 1)Output
"escalate:budget_usd"