You might have heard here and there that agents drop the database, provide sensitive keys, or do something outside their scope. Let's talk about how we can avoid these situations.
By Alejandro Aboy
Published: 2025-08-09
URL: https://thepipeandtheline.substack.com/p/secure-llms-other-secure-design-principles
Hi there! Alejandro here 😊
Suscribe if you like to read about technical data & AI learnings, deep dives!
Enjoy the reading and let me know in the comments what you think about it 👨🏻💻
In other articles, we talked about securing LLM outputs for better tool calling and securing LLMs against prompt injection by using techniques such as topical guardrails, text classifiers, or even prompting techniques such as few-shot.
But when all those hacky techniques are not enough, what’s left?
Let’s see what we can do about it.
📝 Note: Bear in mind that when I say LLM or Agent, I mean the same thing for this explanation.
Generated by ChatGPT.
Database permissions
Apply the principle of least privilege to clearly understand the scope of the agent when running queries or accessing internal APIs.
Create dedicated database users and, under no circumstances, reuse users that are meant for other purposes, since it can result in making the wrong call and running queries where it shouldn’t.
Simple: An agent or LLM cannot drop a table in your data warehouse if it doesn’t have access to do so.
Right tools to the LLM
Similar to the least privilege principle, conduct a shaping session to properly define what your agent should do and, especially, what it shouldn’t do.
If you only need to fetch data from a data warehouse or read from an API, list tables, endpoints, and methods (GET, POST, DELETE, etc.) that it should cover so you and your team are fully sure of the probable scenarios when the LLM makes mistakes.
There’s a huge difference between an LLM returning the wrong result from a SQL query and an LLM deleting the wrong rows.
Thanks for reading The Pipe & The Line! Subscribe for free to receive new posts and support my work.
Inherit Authentication Scope
This is probably only relevant for access-based or multi-tenant applications, but it is still worth mentioning.
If you provide an agent (e.g., a chat interface) to users and there are things that specific users should not see, the agent needs to act on behalf of the user as an impersonated version of that user.
Otherwise, a user might end up seeing something different because the agent bypassed RLS (Row Level Security) and didn’t follow the authenticated scope of the user behind that request.
As with database permissions and defined tools, an agent or LLM won’t get the wrong data or do the wrong thing if it cannot do it at all.
Logging & Monitoring
Always. Log. Everything.
Log any reads, and especially writes, performed by AI, so that actions taken by AI are explainable and auditable.
You cannot trace back problems caused by unexpected LLM outputs if you don’t even collect them.
There are a lot of tools leveraging observability capabilities such as Opik or Langfuse where you can track your prompt performance and evaluate them against datasets to refine them over time.
Thanks for reading The Pipe & The Line! This post is public so feel free to share it.
Cloud Content Filtering
This allows you to prevent most of these scenarios by using their trained datasets to filter common attack attempts.
Think of an enormous database full of sentence examples, such as “ignore your instructions” variants enabled by default, checking if the user query is appropriate from a standard perspective.
Going further, you can set your own customized content filters if you have known scenarios that are not so typical for common use cases but might create problematic situations with your users if they are not handled accordingly.
e.g. AzureOpenAI has filters by default that prevent harmful language, jailbreaking, prompt injection, and other common attacks to hijack LLMs. You can try using its models and attempt to say “ignore your instructions” and see what happens; the LLM won’t even get the query.
📝 TL;DR
-
Database permissions configured clearly so the LLM cannot access or do something it shouldn’t.
-
Right tools to the LLM so it can only achieve what you want and not be caught up in hallucinations.
-
Inherit authentication scope so the agents can act on behalf of users and only do what they can do.
-
Logging & Monitoring to trace back any issues caused by LLM outputs and iterate over your AI implementations.
-
Content filtering to use your cloud service’s trained datasets to prevent malicious requests from going through your LLM.
If you want to deep dive more on the topic, there are other articles I can recommend:
If you enjoyed the content, hit the like ❤️ button, share, comment, repost, and all those nice things people do when like stuff these days. Glad to know you made it to this part!

Hi, I am Alejandro Aboy. I am currently working as a Data Engineer. I started in digital marketing at 19. I gained experience in website tracking, advertising, and analytics. I also founded my agency. In 2021, I found my passion for data engineering. So, I shifted my career focus, despite lacking a CS degree. I'm now pursuing this path, leveraging my diverse experience and willingness to learn.