Skip to content

Getting Started

Frody edited this page Sep 4, 2026 · 2 revisions

Getting Started with AgentGuard

This guide demonstrates setting up AgentGuard in a Java 21 application and Spring Boot 3 service.


1. Maven Installation

Add the dependency to your pom.xml:

<dependency>
    <groupId>io.github.frodygr</groupId>
    <artifactId>agentguard-core</artifactId>
    <version>0.1.0</version>
</dependency>

For Spring Boot projects:

<dependency>
    <groupId>io.github.frodygr</groupId>
    <artifactId>agentguard-spring-boot-starter</artifactId>
    <version>0.1.0</version>
</dependency>

2. Standalone Java Example

import io.github.frodygr.agentguard.core.AgentGuardSuite;

public class AiAgentDemo {

    public static void main(String[] args) {
        // Initialize default suite
        AgentGuardSuite guard = AgentGuardSuite.ofDefaults();

        // Raw input with sensitive PII
        String userQuery = "Please update email to alice.smith@corp.com and charge Visa 4532-0150-1234-5671";

        // Step 1: Secure outgoing prompt
        AgentGuardSuite.GuardedPrompt secured = guard.securePrompt(userQuery);

        System.out.println("Transmitted to LLM:");
        System.out.println(secured.sanitizedPrompt());
        // Outputs: "Please update email to [EMAIL_1] and charge Visa [CREDIT_CARD_1]"

        // Step 2: Simulate response from LLM
        String llmOutput = "Confirmation: [CREDIT_CARD_1] was charged, receipt sent to [EMAIL_1].";

        // Step 3: Restore PII for user
        String restoredOutput = guard.restoreResponse(llmOutput, secured.piiContext());
        System.out.println("Restored to User:");
        System.out.println(restoredOutput);
        // Outputs: "Confirmation: 4532-0150-1234-5671 was charged, receipt sent to alice.smith@corp.com."
    }
}

3. Spring Boot Starter Example

With the starter on your classpath, annotate your AI interaction methods with @SecurePrompt:

@Service
public class ChatAssistantService {

    @SecurePrompt
    public String chat(String userMessage) {
        // userMessage is pre-masked with tokens!
        // Returned response is automatically restored with original PII!
        return openAiClient.generate(userMessage);
    }
}

Clone this wiki locally