Fine-Tuning vs RAG: A Decision Framework for Enterprise Teams
The fine-tuning vs RAG debate misses the point. Both are tools with specific strengths. Here’s a practical framework for choosing the right approach for your use case.
Bill Tanker
Crazy Unicorns
Traditional application security focuses on well-understood attack vectors: SQL injection, XSS, authentication bypass, and authorization flaws. LLM applications introduce entirely new categories of risk. A model that can interpret natural language can be manipulated through natural language. A system that generates text can generate harmful, misleading, or confidential text. Securing LLM applications requires a fundamentally different approach to threat modeling.
We categorize LLM security threats into four groups: prompt injection (manipulating the model’s behavior through crafted inputs), data leakage (extracting training data, system prompts, or retrieved documents through the model’s outputs), unauthorized actions (tricking agent-based systems into performing unintended operations), and output manipulation (causing the model to generate harmful, biased, or misleading content). Each category requires specific defensive measures.
Prompt injection is the most discussed LLM vulnerability, and for good reason — it’s difficult to prevent completely. An attacker crafts input that overrides the system prompt, causing the model to ignore its instructions and follow the attacker’s instead. We implement defense-in-depth with multiple layers: input sanitization that detects and neutralizes common injection patterns, instruction hierarchy that separates system instructions from user input using model-specific delimiters, output validation that checks responses against expected formats and content policies, and behavioral monitoring that flags anomalous response patterns.
No single defense is foolproof. The key insight is that prompt injection is more like spam filtering than SQL injection — you can’t eliminate it with a single fix, but you can reduce the success rate to an acceptable level through layered defenses. We also implement rate limiting and anomaly detection to identify and block systematic injection attempts.
LLM applications often have access to sensitive data — either through RAG retrieval, fine-tuning data, or system prompts that contain business logic. Data leakage occurs when an attacker extracts this information through carefully crafted queries. We prevent data leakage through access control at the retrieval layer (users can only retrieve documents they’re authorized to see), output filtering that detects and redacts sensitive patterns (PII, credentials, internal identifiers), and response boundary enforcement that prevents the model from revealing system prompts or internal instructions.
For RAG systems, we implement document-level access control that maps user permissions to document metadata. Before any retrieved document reaches the model’s context, we verify that the requesting user has permission to access it. This prevents a common attack where users craft queries designed to retrieve documents outside their authorization scope.
Agent-based LLM systems that can take actions — sending emails, querying databases, calling APIs — require additional security measures. We implement tool-level permissions that restrict which actions each user can trigger, parameter validation that ensures tool inputs conform to expected schemas and business rules, confirmation gates that require human approval for high-impact actions, and audit logging that records every action taken by the agent with full context.
The principle of least privilege is especially important for agents. Each agent should have access to the minimum set of tools required for its task. A customer support agent doesn’t need access to the billing system’s write APIs. A document summarization agent doesn’t need access to email sending tools. We define tool access policies declaratively and enforce them at runtime.
We maintain a library of adversarial test cases that we run against every LLM application before deployment. These tests cover known prompt injection techniques, data extraction attempts, authorization boundary violations, and output policy violations. The test suite is continuously updated as new attack techniques are discovered. We also conduct periodic red-team exercises where security engineers attempt to break the system using novel approaches.
Security monitoring for LLM applications goes beyond traditional log analysis. We monitor for unusual query patterns that might indicate injection attempts, response anomalies that suggest the model’s behavior has been manipulated, data access patterns that don’t match normal usage, and cost spikes that might indicate abuse. When anomalies are detected, automated responses can throttle suspicious users, escalate to human review, or temporarily restrict the model’s capabilities.
LLM security is an evolving field, and the threat landscape changes as models become more capable. If you’re deploying LLM applications in an enterprise environment and need help with security architecture, let’s discuss your specific threat model.
We build production-ready AI systems. Book a strategy call to discuss your requirements.
Hello! How can I help?