What is LLM Security?
LLM Security involves implementing protective measures to safeguard LLMs and their infrastructure from unauthorized access, misuse, and adversarial attacks, ensuring the integrity and confidentiality of both the model and data. This is crucial in AI/ML systems to maintain ethical usage, prevent security risks like prompt injections, and ensure reliable operation under safe conditions.How does LLM Security work?
LLM Security can be addressed with a combination of
- LLM Security libraries for run-time security measures
- ABV for the ex-post evaluation of the effectiveness of these measures
1. Run-time security measures
There are several popular security libraries that can be used to mitigate security risks in LLM-based applications. These include: LLM Guard, Prompt Armor, NeMo Guardrails, Microsoft Azure AI Content Safety, Lakera. These libraries help with security measures in the following ways:- Catching and blocking a potentially harmful or inappropriate prompt before sending to the model
- Redacting sensitive PII before being sending into the model and then un-redacting in the response
- Evaluating prompts and completions on toxicity, relevance, or sensitive material at run-time and blocking the response if necessary
2. Monitoring and evaluation of security measures with ABV
Use ABV tracing to gain visibility and confidence in each step of the security mechanism. These are common workflows:- Manually inspect traces to investigate security issues.
- Monitor security scores over time in the ABV Dashboard.
- Validate security checks. You can use ABV scores to evaluate the effectiveness of security tools. Integrating ABV into your teamโs workflow can help teams identify which security risks are most prevalent and build more robust tools around those specific issues. There are two main workflows to consider:
- Annotations (in UI). If you establish a baseline by annotating a share of production traces, you can compare the security scores returned by the security tools with these annotations.
- Automated evaluations. ABVโs model-based evaluations will run asynchronously and can scan traces for things such as toxicity or sensitivity to flag potential risks and identify any gaps in your LLM security setup. Check out the docs to learn more about how to set up these evaluations.
- Track Latency. Some LLM security checks need to be awaited before the model can be called, others block the response to the user. Thus they quickly are an essential driver of overall latency of an LLM application. ABV can help dissect the latencies of these checks within a trace to understand whether the checks are worth the wait.
Getting Started
Example: Anonymizing Personally Identifiable Information (PII) Exposing PII to LLMs can pose serious security and privacy risks, such as violating contractual obligations or regulatory compliance requirements, or mitigating the risks of data leakage or a data breach. Personally Identifiable Information (PII) includes:- Credit card number
- Full name
- Phone number
- Email address
- Social Security number
- IP Address
1) Install packages
In this example we use the open source library LLM Guard for run-time security checks. All examples easily translate to other libraries such as Prompt Armor, NeMo Guardrails, Microsoft Azure AI Content Safety, and Lakera. First, import the security packages and ABV tools.2) Anonymize and deanonymize PII and trace with ABV
We break up each step of the process into its own function so we can track each step separately in ABV. By decorating the functions with@observe(), we can trace each step of the process and monitor the risk scores returned by the security tools. This allows us to see how well the security tools are working and whether they are catching the PII as expected.