Aulafy
Courses/Advanced and secure RAG/Structured responses with citations

Structured responses with citations

To use RAG in an SMB or serious project, "pretty text" is not enough. You need a contract: answer, evidence, confidence, missing fields, and a clear output when the context is insufficient.

  • Design a validatable response contract.
  • Enforce citations linked to retrieved chunks.
  • Prevent hallucinations with "I don't have sufficient evidence".
TerminalCode
{
  "answer": "Puedes devolver el producto durante 14 días naturales.",
  "confidence": "high",
  "citations": [
    {
      "document_id": "politica-devoluciones",
      "section": "Devoluciones",
      "page": 3,
      "quote": "plazo de 14 días naturales"
    }
  ],
  "missing_fields": [],
  "cannot_answer": false
}

Generation rules

  • Answer only with retrieved context.
  • Every important claim must have a citation.
  • If data is missing, populate `missing_fields`.
  • If there is no evidence, set `cannot_answer`.
  • Validate JSON before displaying it.
TerminalCode
regla_no_se:
  si:
    retrieved_chunks < 2
    o no hay cita directa
    o las fuentes se contradicen
  entonces:
    cannot_answer: true
    answer: "No tengo evidencia suficiente en los documentos recuperados."
    missing_fields: ["fuente verificable"]

Official sources

  • Qdrant documentation
  • Qdrant hybrid queries
  • Open WebUI documentation