Add guardrails module: prompt injection defences (document filter, tool policy, output validation) measured against an always-obeying stub model

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JXVi2GMQ7bR5EmbUFdDj7N
This commit is contained in:
Claude
2026-10-09 06:50:23 +00:00
parent cc2a1b8bcb
commit b0bba995e6
35 changed files with 1349 additions and 0 deletions
@@ -0,0 +1,29 @@
package com.ankurm.guardrails;
import java.util.ArrayList;
import java.util.List;
/** Drops retrieved chunks that match {@link InjectionHeuristics} before they reach the prompt. */
public final class DocumentGuard {
public record Result(List<Doc> kept, List<String> dropped) {
}
private DocumentGuard() {
}
public static Result filter(List<Doc> docs) {
List<Doc> kept = new ArrayList<>();
List<String> dropped = new ArrayList<>();
for (Doc d : docs) {
List<String> hits = InjectionHeuristics.matches(d.text());
if (hits.isEmpty()) {
kept.add(d);
}
else {
dropped.add(d.id() + " (" + String.join(", ", hits) + ")");
}
}
return new Result(kept, dropped);
}
}