Guardrails for LLM tools in production
Practical guardrails I use when PHP services call DeepSeek and expose agent tools: consent, CSRF, rate limits, validation, and confirmation.
- LLM
- Security
- PHP
- DeepSeek
- MCP
Shipping an LLM feature is easy. Shipping one that behaves in production is mostly about the boring controls around the model.
Two systems I have worked on forced that lesson: the FastFormat.io AI Document Formatter and the Borderless Fetch MCP server. Both call DeepSeek. Both treat the model as an untrusted coworker with a typed job description.
Start with the request, not the prompt
On FastFormat.io, the AI Document Formatter is a PHP JSON endpoint built in 2025. Before DeepSeek sees anything, the request path covers consent, CSRF protection, rate limiting, and validation.
Those checks are not “AI safety” theatre. They are ordinary web security plus an explicit user consent step for sending document content to a model API. If the request fails those gates, there is no chat completion to debug.
System prompts are constraints, not vibes
The formatter uses system prompts to keep the model inside the document-formatting job. System prompts do not replace validation. They reduce how often the model wanders; they do not stop a crafted or accidental bad request from reaching the API.
I treat system prompts as one layer: useful, necessary, insufficient on their own.
Tools need schemas and scopes
On the Borderless Fetch MCP server, the PHP /mcp JSON-RPC surface exposes about 16 schema-typed tools plus borderless:// resources and guided prompts. Schema typing makes malformed tool calls fail early. Role and permission scoping keeps read-heavy callers away from mutating tools they should not see.
An in-app DeepSeek chatbot calls those tools. That is the point of MCP here: the model does not get a blank cheque against orders, wallets, or Paystack top-ups.
Confirm before state changes
Any tool that changes state requires explicit confirmation. Rate limiting sits alongside that. Together they blunt two common failure modes: an agent that retries too eagerly, and an agent that leaps from “I can do this” to “I already did this”.
A checklist I actually use
- Consent — especially when user content leaves your boundary for a model API.
- CSRF — for browser-facing JSON endpoints.
- Rate limits — on both human-facing and agent-facing surfaces.
- Validation — before the model and again on tool arguments.
- Permission scoping — least privilege for tools and resources.
- Confirmation — for mutations, every time.
- System prompts — narrow the job; do not rely on them alone.
What this is not
I am not claiming these patterns remove all risk. I am saying they are the minimum I am willing to ship when PHP services call DeepSeek or expose MCP tools that can touch money and fulfilment.
If you only add a prompt and an API key, you have a demo. If you add consent, CSRF, rate limits, validation, scoping, and confirmation, you have something closer to production.