LLM Guard tutorial: scan prompts and responses
Learn how LLM Guard scans prompts and responses, with examples of PII anonymization, prompt injection detection and Python integration.
Player not loading? Watch on YouTube
Uploaded on August 11, 2024, this tutorial explains LLM Guard through a Hugging Face playground and a Python integration example. The source does not specify a library version, so the demonstrated behavior belongs to that dated walkthrough.
The speaker places scanners before and after an LLM call. Input checks can flag personal information, prompt injection or requests for code. In the playground example, anonymization redacts a name and email address while leaving an address intact; the speaker explains that users can configure which information to remove. A separate prompt injection example triggers a detection result but leaves the displayed text unsanitized. Detection does not necessarily mean a scanner rewrites the prompt.
The code example requests SQL containing a username and email address. Input scanning returns a sanitized prompt, validation results and scores. The application sends that sanitized prompt to the LLM, then scans its response with deanonymization and sensitive-information checks. The speaker reports that the sensitive check flags the output after deanonymization.
The sample prints failed checks to the console. The speaker discusses termination or routing results elsewhere as application choices. This is an open source guardrail tutorial, rather than a demonstration of running a local LLM or proof that the checks prevent every unsafe response.