Skip to main content
Version: 1.14.0

Change requests by rule and call your own check

Some changes belong on every model call, whatever the application sends: a header your own systems need, a temperature your team has agreed on, a cost tag for every request. And some checks are specific to your company, such as asking an internal service whether this user may send this request. From 1.14.0, a workspace can do both on DVARA without writing a gateway plugin:

  • Request rules set, remove or rename one header or one JSON body field, each only when its condition holds.
  • A callout sends each POST request to your own service, which answers continue, continue with changes, or refuse.

DVARA governs the changed request. Model access, budgets, policy, PII handling, guardrails and routing all run after the rules and the callout, so a rule that changes the model is still judged by the policy, and text the callout adds is still checked for PII.

Enterprise only

Not included in DVARA Open Source. It runs with or without a licence.

Request rules are off by default. Each workspace turns them on for itself. They apply to the LLM plane's /v1 requests only.

Add a rule​

  1. Open Governance → Request Rules in Flightdeck. An owner or policy-admin chooses the workspace; a workspace admin works on their own workspace.
  2. Turn on Apply request rules and the callout to this workspace's requests.
  3. Add a rule and click Save.

Each rule row has these fields:

FieldWhat to enter
Name1 to 64 characters: letters, digits, spaces and _ . : -. The name is what the audit record shows.
ChangesHeader or Body field
DoesSet, Remove or Rename
Header or fieldA header name, or a body field as a dot path such as temperature or metadata.team
ValueFor Set: the value to write
New nameFor Rename: the new header name or body path
Only whenA CEL condition. Empty means always

For example, these three rules tag every request, cap the temperature for GPT models, and drop a header an old client still sends:

NameChangesDoesHeader or fieldValueNew nameOnly when
tag-teamHeaderSetX-Dvara-Tagsteam=payments,env=prod
gpt-temperatureBody fieldSettemperature0.2string(request.body.model).startsWith("gpt-")
drop-legacyHeaderRemovex-legacy-client

The next request on /v1/chat/completions from that workspace reaches the provider with temperature: 0.2 when it asks for a GPT model, and its cost record carries the tags team=payments and env=prod. The audit trail gets one REQUEST_TRANSFORMED event naming the rules that changed it.

A save checks every rule and compiles every condition. If anything is wrong, nothing is saved: the form comes back as you typed it, with each problem listed. Each save writes WORKSPACE_REQUEST_RULES_UPDATED with the settings before and after. The signing secret is never in it; the event only says whether one is set.

How rules are applied​

  • Rules run in order. Each rule sees what the rules before it did. A rule that would change nothing is not reported as applied.
  • Header rules work on every request.
  • Body rules need a JSON object body of at most 10 MiB. A form, a file upload, a longer body or a body that is not a JSON object goes on as it came, and body rules skip it.
  • A body field is a dot path of up to 8 names. Each name uses letters, digits, _ and -. Set creates the objects on the path, but never overwrites a value that is not an object to reach deeper.
  • A Set value that reads as JSON is written as JSON: 0.2 is a number, true a boolean, "text" a string and {...} an object. Anything else is written as text.
  • A workspace can have at most 50 rules. A header value is at most 4,096 characters, a body value at most 16,384, and a condition at most 2,000.

Headers no rule can change​

These headers are kept as the caller sent them. No rule may name one, as the source or the target, and the callout cannot change them either:

  • credential headers: Authorization, Proxy-Authorization, x-api-key, api-key, x-goog-api-key and Cookie;
  • Host, and the headers that frame the body: Content-Length, Content-Type, Content-Encoding, Transfer-Encoding, Connection, Upgrade, TE, Trailer, Keep-Alive and Expect;
  • forwarding, trace and session headers: Forwarded, X-Real-IP, every X-Forwarded-* header, X-Trace-ID and X-Session-Id;
  • every X-Dvara-* and X-Gateway-* header, with one exception below.

X-Dvara-Tags is the exception, for rules only. A rule may set, remove or rename it, so a workspace can tag every request. The value must be valid tags: at most 16 key=value pairs, separated by commas. A Set value is checked when you save. The header's value after all the rules is checked on every request; a bad value refuses the request with 400 invalid_tags and writes REQUEST_RULES_REFUSED. On /v1/chat/completions the tags are then written into the body's metadata.tags, so the cost record and tag-scoped budgets use them. A tag set by a rule replaces a caller's tag of the same name; the caller's other tags stay. On other APIs the header is set and nothing more. The callout may never change X-Dvara-Tags: tags decide who pays, and a remote service should not move spend between teams.

Write a condition​

Conditions are CEL expressions over one variable, request:

FieldWhat it holds
request.methodThe HTTP method, such as POST
request.pathThe path, such as /v1/chat/completions
request.workspace_idThe workspace id
request.headersHeader names in lower case, mapped to their value. Credential headers are left out
request.bodyThe JSON body, as maps and lists. Whole numbers are integers

Every field is dynamic, so call string(...) before a string method. Some examples:

string(request.body.model).startsWith("gpt-")
"x-team" in request.headers
request.body.stream == true
request.path == "/v1/messages"

A condition that does not compile is refused on save. One that fails while it runs, for example because a field is missing, counts as false, and its rule does not apply.

Call your own service before the gateway governs the request​

Fill in the Callout part of the page:

FieldDefaultWhat it does
Callout URLnoneYour service's http or https address, up to 2,048 characters
Time limit (ms)100050 to 10,000. The whole call is held to this limit
When it fails or times outRefuse the requestRefuse the request (fail closed) or Let the request through (fail open)
Signing secretnoneWhen set, each call is signed. Leave the field blank to keep the stored secret; tick Remove the signing secret to clear it. It is never shown again

The callout runs after the rules, on POST requests only. Every model call is a POST. A GET, such as GET /v1/models, gets the header rules but is never sent to the callout, and a fail-closed callout does not refuse it.

The URL is checked with the same egress rules as webhooks and guardrail plugins, when you save and again when the gateway connects. Loopback, link-local and cloud metadata addresses are always refused. A private-network address is allowed only when the saving page allows it: dvara.admin.egress.allow-private-networks (default true) when an owner or policy-admin saved it, and dvara.portal.egress.allow-private-networks (default false) when a workspace admin did. The gateway follows no redirects.

What your service receives​

POST /check HTTP/1.1
Host: request-check.internal.example.com
Content-Type: application/json
X-Trace-ID: 7f3a9c2e5b1d4e8fa0c6d2b9e4f1a3c7
X-Gateway-Signature: sha256=5d41402abc4b2a76b9719d911017c592...
{
"workspace_id": "ws-payments",
"trace_id": "7f3a9c2e5b1d4e8fa0c6d2b9e4f1a3c7",
"sent_at": 1762070400000,
"method": "POST",
"path": "/v1/chat/completions",
"headers": {"content-type": "application/json", "x-dvara-tags": "team=payments,env=prod"},
"body": {"model": "gpt-4o", "temperature": 0.2, "messages": [{"role": "user", "content": "Summarise invoice 4471"}]},
"rules_applied": ["tag-team", "gpt-temperature"]
}

The body is the request after the rules. It never holds a credential header: the caller's API key is not sent. sent_at is in milliseconds since the epoch. X-Gateway-Signature is present only when a signing secret is set; it is the hex HMAC-SHA256 of the body, as guardrail plugins are signed. Check it before you trust the body.

What your service answers​

Answer with status 200 and one of these bodies:

AnswerEffect
{"action": "continue"}Send the request on as it is
{"action": "continue", "set_headers": {"x-risk-tier": "low"}, "remove_headers": ["x-debug"], "body": {...}}Send it on with changes. Each of set_headers (an object of header names to text values), remove_headers (a list of names) and body (a JSON object that replaces the whole body) is optional
{"action": "refuse", "status": 403, "message": "Payments data is not allowed in this workspace"}Refuse it. The status must be 400 to 499; any other or a missing status reads as 403. The message is cleaned and cut to 500 characters

The whole answer is checked before anything is applied. A protected header in set_headers or remove_headers is ignored, and the audit record lists it. A new body for a request whose body is not JSON is outside the contract.

A refused request gets the callout's status, with code request_refused, in the error shape of the API the caller used (OpenAI-style on /v1/chat/completions, Anthropic-style on /v1/messages):

{
"error": {
"message": "The workspace's request check refused this request: Payments data is not allowed in this workspace",
"type": "permission_error",
"code": "request_refused"
}
}

The type is permission_error for 403, else invalid_request_error. Nothing is sent to a provider, and REQUEST_REFUSED_BY_CALLOUT is written.

When the callout fails​

The callout fails when it does not answer within the time limit, answers a status other than 200, answers outside the contract, or cannot be reached; when its address is refused; when the gateway cannot read the signing secret; or when the answer or the request body is larger than 10 MiB.

  • Refuse the request (the default): the caller gets 503 request_check_unavailable, type server_error, with the message "The workspace's request check could not be reached, and this workspace refuses requests it cannot check. Try again later."
  • Let the request through: the request goes on with the rules' changes only.

Either way REQUEST_CALLOUT_FAILED records the reason, the fail mode and the outcome. Choose Refuse the request when the callout enforces a rule you must not skip. Choose Let the request through when it only adds context, so an outage of your service does not stop model traffic.

Error codes​

StatustypecodeWhen
400invalid_request_errorinvalid_tagsThe rules left an X-Dvara-Tags value that is not valid tags
400 to 499permission_error (403) or invalid_request_errorrequest_refusedThe callout answered refuse
503server_errorrequest_check_unavailableThe callout failed and the workspace refuses requests it cannot check

Audit events​

Each event names what changed, never the values.

EventWhenWhat it records
REQUEST_TRANSFORMEDThe rules or the callout changed a requesttrace_id, method, path, rules_applied (rule names, in order), the header names set and removed, the body fields changed (body_fields), whether the callout replaced the body, and with a callout what it did (continue or changed), its latency and any protected headers it asked to change
REQUEST_RULES_REFUSEDThe rules left invalid tags; the caller got 400 invalid_tagsAs above, plus reason: invalid_tags
REQUEST_REFUSED_BY_CALLOUTThe callout refusedAs above, plus the status and the callout's message
REQUEST_CALLOUT_FAILEDThe callout failedAs above, plus callout_reason (timeout, bad_status, call_failed, malformed_response, egress_refused, secret_unreadable, answer_too_large or body_too_large), fail_mode (closed or open) and outcome (refused or passed)
WORKSPACE_REQUEST_RULES_UPDATEDSomeone saved the workspace's rules in FlightdeckThe settings before and after, without the secret, and who saved them

Find the request's own GATEWAY_RESPONSE record by its trace_id. The gateways also count each callout in the Prometheus counter gateway_request_callout_total{outcome, reason}: outcome is continue, changed, refused or failed, and reason is the failure reason or none.

Who can change request rules​

RoleCan do
owner, policy-adminChoose any workspace, change its rules and callout
Workspace adminChange their own workspace's rules and callout
developer, viewerRead their workspace's rules; no save
billing-adminNo access

Turn request rules off for a whole gateway​

Set dvara.llm-gateway.request-rules.enabled=false (environment variable DVARA_LLM_GATEWAY_REQUEST_RULES_ENABLED=false) on a gateway, and it applies no rules and calls no callout for any workspace. The default is true, which still leaves each workspace off until it turns rules on. A workspace with rules off, or with no rules and no callout, has its requests passed on unchanged and unread.

Configuration as code​

A workspace's request rules travel with it in a configuration export and import. The export writes the signing secret as *** and leaves out the private-network setting. An import checks the rules, conditions and callout URL as the page does, refuses any secret other than ***, and keeps the stored secret when the file says *** and the URL has not changed. See GitOps.