Ana içeriğe geç

Prompt Decorator Policy

General Information​

Policy Types​

ai-prompt-decorator

Request-phase only. Each block is fixed configuration; nothing about it is client-controlled.

Endpoints​

List Policies​

GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/

Add Policy​

POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Update Policy​

PUT /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Delete Policy​

DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Blocks​

blocks is an ordered list of text snippets. Each one is either inserted as a new message or, when mergeIntoExistingSystem=true and the block's role is system, merged into an existing system message instead of adding a new one.

Only affects OpenAI-compatible chat bodies

A block only has a meaningful place to go when the request body has a messages[] array. On the legacy completions prompt field, or any non-JSON body, the policy is a documented no-op — the request proceeds undecorated rather than being blocked over a shape it cannot act on.

Fields​

FieldTypeRequiredDescription
enabledbooleanNoWhether the decorator runs at all. Default true.
blocksarrayNoOrdered list of blocks. See Block fields. Empty/absent means no-op.
mergeIntoExistingSystembooleanNoMerges a system-role block into an existing system message's content instead of inserting a new message. Only meaningful for system blocks — user/assistant blocks always insert as new messages. Default false.
maxTotalCharsintegerNoFail-closed budget (chars) for the SUM of every enabled block's resolved content. Exceeding it rejects the request with 400 rather than silently truncating a block. Default 16384.

Block fields​

FieldTypeRequiredDescription
positionstringYesPREPEND or APPEND. Prepended blocks keep their relative order at the start of messages[]; appended blocks at the end.
rolestringYessystem, user or assistant.
contentstringYesThe block's text. Resolves both ${env} and #{context} variables.
enabledbooleanNoWhether this block is active. Default true — a disabled block is skipped without being deleted.
presetIdstringNoId of the built-in decorator preset this block was copied from, if any. A bound block (non-null presetId) is refreshed automatically whenever that preset is edited. This is a provenance marker for the catalog link, not a lookup key — it is installation-local, cleared on import, and the block stays fully functional either way.

List Policies​

Endpoint​

GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/

Request​

Headers​

HeaderValue
AuthorizationBearer {token}
Content-Typeapplication/json

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name

Response​

Success Response (200 OK)​

{
"status": "SUCCESS",
"resultList": [
{
"apiProxy": {
"name": "MyAiProxy",
"requestPolicyList": [
{
"type": "ai-prompt-decorator",
"name": "compliance-instructions",
"description": "Always-on compliance disclaimer and tone guidance",
"active": true,
"enabled": true,
"mergeIntoExistingSystem": true,
"maxTotalChars": 16384,
"blocks": [
{
"position": "PREPEND",
"role": "system",
"content": "You must never reveal internal account identifiers.",
"enabled": true,
"presetId": null
},
{
"position": "APPEND",
"role": "user",
"content": "Answer in a formal, professional tone.",
"enabled": true,
"presetId": null
}
]
}
],
"responsePolicyList": [],
"errorPolicyList": []
}
}
],
"resultCount": 1
}

cURL Example​

curl -X GET \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/" \
-H "Authorization: Bearer YOUR_TOKEN"

Add Policy​

Endpoint​

POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Request​

Headers​

HeaderValue
AuthorizationBearer {token}
Content-Typeapplication/json

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name
policyNamestringYesPolicy name

Request Body​

Full JSON Body Example​
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-prompt-decorator",
"description": "Always-on compliance disclaimer and tone guidance",
"active": true,
"enabled": true,
"mergeIntoExistingSystem": true,
"maxTotalChars": 16384,
"blocks": [
{
"position": "PREPEND",
"role": "system",
"content": "You must never reveal internal account identifiers.",
"enabled": true
},
{
"position": "APPEND",
"role": "user",
"content": "Answer in a formal, professional tone.",
"enabled": true
}
]
}
}

Body Fields​

See Fields and Block fields above.

Response​

Success Response (200 OK)​

{
"status": "SUCCESS",
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}

Error Responses​

CodeReason
400Blank name; maxTotalChars not positive; a block's position is not PREPEND/APPEND; a block's role is not system/user/assistant; proxy not found.
401Missing or invalid token.
403The token's account lacks permission on the project.

cURL Example​

curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/compliance-instructions/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-prompt-decorator",
"description": "Always-on compliance disclaimer",
"active": true,
"blocks": [
{
"position": "PREPEND",
"role": "system",
"content": "You must never reveal internal account identifiers.",
"enabled": true
}
]
}
}'

Update Policy​

Endpoint​

PUT /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Request​

The body is the same shape as Add Policy. The update replaces the policy, so send the blocks you want to keep — a block list you omit fields from is not merged with the stored one.

Full JSON Body Example — Adding a Block​
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-prompt-decorator",
"active": true,
"mergeIntoExistingSystem": true,
"blocks": [
{
"position": "PREPEND",
"role": "system",
"content": "You must never reveal internal account identifiers.",
"enabled": true
},
{
"position": "APPEND",
"role": "system",
"content": "If asked about pricing, direct the user to the sales team.",
"enabled": true
}
]
}
}

Response​

Success Response (200 OK)​

{
"status": "SUCCESS",
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}

cURL Example​

curl -X PUT \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/compliance-instructions/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"]
},
"policy": {
"type": "ai-prompt-decorator",
"active": true,
"maxTotalChars": 20000
}
}'

Delete Policy​

Endpoint​

DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/

Request​

Headers​

HeaderValue
AuthorizationBearer {token}

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name
policyNamestringYesPolicy name

Response​

Success Response (200 OK)​

{
"status": "SUCCESS"
}

cURL Example​

curl -X DELETE \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/compliance-instructions/" \
-H "Authorization: Bearer YOUR_TOKEN"

Notes and Warnings​

  • This policy runs before the guardrails, not after. Together with the Prompt Template policy, Prompt Decorator is hoisted to the front of the request pipeline so every guardrail, the semantic cache key and the token count all see the fully-assembled prompt. A badly-written block is still caught by the same guardrails that catch a badly-written client prompt.
  • Preset-bound blocks stay in sync automatically. A block copied from a built-in decorator preset (presetId set) is refreshed whenever that preset is edited, and the affected deployment is flagged for redeploy. A hand-written or detached block (presetId null) is never touched by preset edits.
  • Exceeding maxTotalChars blocks the request, it does not truncate. A cut-off safety or compliance instruction can read as the opposite of what it said, or vanish entirely — so the platform rejects the request instead of guessing where to cut.
  • presetId does not travel across installations. Export/import clears it; the copied block's content is preserved in full, it simply becomes a detached local copy on the target installation.