Prompt Engineering
Advanced

RAG and Red-Team Lab

Test retrieval quality and prompt-injection resistance for an internal knowledge assistant.

50 min
2 sections
rag
prompt-injection
security
retrieval
1
2

01. Evaluate retrieval before generation

Section 1 of 2

If the model does not receive the right source, the prompt cannot produce a grounded answer. Build a golden query set that names the expected documents, required answer facts, and sources that must not be used.

typescript
type GoldenQuery = {
  query: string;
  expectedSources: string[];
  requiredFacts: string[];
  disallowedSources?: string[];
};

const goldenQueries: GoldenQuery[] = [
  {
    query: "How do we rotate billing webhook secrets?",
    expectedSources: ["runbooks/billing-webhooks.md"],
    requiredFacts: [
      "create new secret",
      "deploy dual verification",
      "rotate provider dashboard",
      "remove old secret after verification",
    ],
  },
];
Back to Course