Skip to content

Reference architecture

Government digital services AI assistant

A question-answering assistant for public services, grounded in official policy documents, with citations, access control and an audit trail.

Residents ask about benefits, permits and deadlines in their own words. Answers must come from current official documents, cite them, refuse when the documents do not answer, and never reveal another person's case data. Staff see the same assistant with access to internal guidance.

This is a design reference for the encyclopedia, not a deployed service. Each article still explains its concept on its own.

Answering a question

  1. API gateway: Authenticate the resident, check their budget, attach their permissions.
  2. Response and semantic cache: Look for an exact or equivalent answer within the resident's scope.
  3. Retrieval: On a miss, retrieve permitted policy passages with their sources.
  4. Assistant service: Assemble instructions, history and passages within the context budget.
  5. Model providers: Generate a structured answer, falling back to another provider on failure.
  6. Output checks: Validate citations and content, or return a clear no-answer.
  7. Response and semantic cache: Store the validated answer for equivalent future questions.
  8. Observability and evaluation: Record the steps, tokens and outcome without personal data.

Publishing a new policy document

  1. Document ingestion: Parse the new policy document and split it into cited chunks.
  2. Document ingestion: Embed changed chunks and replace the previous version's vectors.
  3. Response and semantic cache: Invalidate cached answers that cited the old version.
  4. Observability and evaluation: Run the evaluation set before the change reaches residents.

Components

API gateway

Authenticates the caller, applies per-user and per-tenant rate limits, and attaches the caller's permissions to the request.

  • Budgets per user so one client cannot exhaust the model quota
  • Keys and tokens never reach the browser

Read

  • Managing provider API keysComing soon
  • Spending budgets and per-user quotasComing soon
  • Unbounded consumption and denial of walletComing soon

Assistant service

Runs one request: checks the caches, retrieves documents, assembles the prompt, calls the model and validates the answer.

  • Treats retrieved text as data, never as instructions
  • Keeps conversation history within the context budget

Read

  • Building a context assembly pipelineComing soon
  • Budgeting the context windowComing soon
  • Managing conversation historyComing soon
  • Separating instructions from dataComing soon

Response and semantic cache

Returns a stored answer for a repeated or equivalent question, scoped so one tenant's answers never serve another.

  • Similarity thresholds tuned on real questions, not guessed
  • Invalidation when a policy document changes
  • Poisoning: only cache answers that passed validation

Read

  • Exact-match LLM response cachingComing soon
  • Selecting similarity thresholdsComing soon
  • Multi-tenant semantic cachingComing soon
  • Semantic cache invalidationComing soon
  • Semantic cache poisoningComing soon

Retrieval

Finds the policy passages that answer the question, filtered to documents the caller may see.

  • Access control applied in the query, not after it
  • Chunks carry their source and effective date for citations

Read

  • The RAG request flow end to endComing soon
  • Document-level access control in RAGComing soon
  • Metadata filtering with vector searchComing soon
  • Vector search in PostgreSQL with pgvectorComing soon

Model providers

Generates the answer through a provider interface, with timeouts, retries and a fallback provider.

  • Structured output validated before use
  • Fallback changes behaviour: test prompts on every provider

Read

  • Designing a model provider interfaceComing soon
  • Falling back to another model or providerComing soon
  • Structured output and schema validationComing soon
  • Porting prompts between modelsComing soon

Output checks

Checks the answer before it is shown: every claim cited, no personal data, no unsafe links, and a clear refusal when the sources do not answer.

  • Model output rendered as text, never as HTML
  • No-answer is a valid, tested outcome

Read

  • Citations and answer attributionComing soon
  • Handling questions the documents cannot answerComing soon
  • Insecure output handlingComing soon
  • Data exfiltration through rendered outputComing soon
  • Keeping sensitive data out of prompts and logsComing soon

Document ingestion

Parses new and changed policy documents, chunks them, embeds them and replaces the previous version.

  • Incremental updates so a changed page re-embeds only what changed
  • Embedding model versions recorded with each vector

Read

  • Parsing documents for retrievalComing soon
  • Chunking strategiesComing soon
  • Incremental ingestion and deletionsComing soon
  • Building an embedding pipelineComing soon
  • Versioning embeddings when the model changesComing soon

Observability and evaluation

Records each request's retrieval, cache and model steps with token usage, and runs regression evaluations before prompt or model changes ship.

  • Logs redact personal data and secrets
  • Evaluation sets include questions the documents cannot answer

Read

  • Counting tokens and tracking cost per requestComing soon
  • Evaluating retrieval and answer qualityComing soon
  • Regression testing promptsComing soon
  • Semantic cache observabilityComing soon

Threat model

The attacks this system is designed against: prompt injection through documents and questions, data leakage across users, and abuse of the model budget.

  • Indirect injection through uploaded or crawled documents
  • The system prompt is not a secret store

Read

  • Threat modeling AI applicationsComing soon
  • The OWASP Top 10 for LLM applicationsComing soon
  • Indirect prompt injectionComing soon
  • System prompt leakageComing soon