A model response is not authorization
The moment an AI application can act — look up a record, update a ticket, issue a refund, send a message — every model response becomes part of a security-sensitive workflow. And the most common design mistake I see is t
The moment an AI application can act — look up a record, update a ticket, issue a refund, send a message — every model response becomes part of a security-sensitive workflow. And the most common design mistake I see is treating the model's output as the decision.
A model response is not authorization. A valid tool call is not proof the action should execute. Those two sentences organize everything below.
What a gateway should own
A gateway sits between your application and the model providers, and it is genuinely good at request-shaped questions:
- Authentication and keys. One integration key instead of provider credentials scattered through every service. Secret manager, never committed, one key per workload, rotated when ownership changes, limits set at the narrowest useful scope, revoked when the workload dies, never printed in a log.
- Request policy. Rate and budget limits, guardrails, routing — applied in a legible order, each control with one owner and one observable failure mode.
- Evidence. Request ID, model and route, status, usage, latency, guardrail and validation outcomes — metadata, not raw prompts warehoused in a log pipeline.
What it must not own
Whether this user may touch that record. Whether this refund is within policy. Whether this tool may change state at all. Those decisions need tenant data and business rules that live only in the application, so the application handles every tool call as untrusted input, in a fixed order:
- Is the tool allowed for this user?
- Do the arguments validate against the tool's schema?
- Does the action's risk tier require human approval?
- Only then: execute — with idempotency keys on anything state-changing, because retries duplicate side effects.
Tools belong in an explicit registry, tiered by risk: read-only lookups at the bottom, destructive actions at the top behind approval and step-up authentication. The model never invents a tool name, and there is no generic tool that reaches the database.
Valid JSON is not a verdict
Structured output is parseable, not trustworthy. Validate required fields, enums, ranges, lengths, unknown fields under strict schemas, tenant identifiers — and the business rules. Authorize after schema validation, because a well-formed identifier does not prove the caller owns the record. Test the rejection set on purpose: missing field, invented enum value, out-of-range number, extra property, and the response that is perfectly valid and belongs to a different tenant. Replay those fixtures whenever a prompt, model or routing rule changes.
Start small
Begin with a low-risk, read-only workflow — classification, lookup. Wire the key and a small registry, validate arguments and final JSON, review the metadata. Expand gradually to approved write actions. The gateway gives those controls a clean boundary and a log that can tell a rejected key from a blocked prompt from an unauthorized action; it does not replace the controls themselves, and honest designs say so.
The full design — decision tables, the key checklist, the worked validation pipeline — is in the nRouter engineering post "Secure LLM Gateway: API Keys, Tool Calls, and JSON Validation": https://nrouter.ai/blog/engineering/secure-llm-gateway-production-ai
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.