Generate Grounded Knowledge Base Answers

OpenAI

Answers questions using your Needle Collection, providing human-readable responses, inline citations, coverage scores, and a structured payload for evaluation.

Knowledge BaseQuestion AnsweringData GovernanceHallucination Checking

This workflow answers natural language questions using a Needle Collection as a knowledge base. It returns a human-readable answer with inline citations and a machine-readable JSON bundle ready to feed into an evaluator or hallucination checker.

It does three things:

  1. Accepts a user question via a manual trigger.
  2. Searches your Needle Collection for relevant passages and composes a grounded, cited answer with a knowledge base coverage rating.
  3. Outputs a structured evaluator payload that can be passed directly to a downstream evaluation workflow.

What you need

  1. A Needle account.
  2. A Needle Collection with documents uploaded (your knowledge base).
  3. The collection ID, which you set once in the COLLECTION_ID workflow variable.

How the flow works

NodeDescription
Manual TriggerCollects the user's question and an optional maximum results parameter (defaults to 5). This is the only runtime input; the knowledge base is configured once via the COLLECTION_ID variable.
AI Q&A AgentReceives the question and uses the collection search tool to retrieve relevant passages. The agent is instructed to answer strictly from retrieved context, never fabricate facts, and cite source documents inline. It classifies coverage as HIGH, MED, LOW, or NONE, and prepends a governance header. The AI model is pinned to a low temperature to ensure stable structured outputs.
Output NormalizerTakes the AI agent's flat string outputs and assembles the final structured format. It splits source names and snippets, pairs them into a sources array, and builds the evaluator payload object.

Output

The workflow produces a single JSON object with this exact shape:

FieldTypeDescription
answer_textStringThe full answer, starting with a governance header line followed by the cited answer body.
kb_coverageStringOne of HIGH, MED, LOW, or NONE, indicating how well the knowledge base covered the question.
sourcesArrayEach element contains the source name and snippet from the retrieved documents.
evaluator_payloadObjectContains the original prompt, context docs, model answer, and coverage score. This object is designed to plug directly into an output evaluator workflow.

Notes

  1. The COLLECTION_ID is a workflow variable, not a runtime input. This is by design because knowledge base Q&A workflows typically target one collection. Set it once when you configure the workflow.
  2. The failure semantics are explicit: NONE means no relevant documents were found, LOW or MED means partial coverage, and HIGH means full coverage. Your downstream evaluator can use this coverage score to set different review thresholds.
  3. The AI agent can search multiple times and rephrase queries for better retrieval coverage.
  4. All intermediate fields between the AI and Code node use a specific raw suffix to make run logs self-documenting and distinguish raw AI output from the final structured response.

Want to showcase your own workflows?

Become a Needle workflow partner and turn your expertise into recurring revenue.

Try Needle today

Streamline AI productivity at your company today

Join thousands of people who have transformed their workflows.

Agentic workflowsAutomations, meet AI agents
AI SearchAll your data, searchable
Chat widgetsDrop-in widget for your website
Developer APIMake your app talk to Needle
    Needle LogoNeedle
    Like many websites, we use cookies to enhance your experience, analyze site traffic and deliver personalized content while you are here. By clicking "Accept", you are giving us your consent to use cookies in this way. Read our more on our cookie policy .