How to Enrich Workflow Data with Knowledge Base Queries

Use Knowledge Base queries mid-workflow to add context from your documents to any process.

What This Integration Does

Most workflows have a moment where they need information that isn't on the input record. An order-processing flow needs to know shipping restrictions for the product category. A claim-handling flow needs the policy wording that applies to a particular customer tier. A support flow needs the troubleshooting steps for a particular product. Rather than hand-coding all of that into the workflow, a mid-flow Knowledge node in Query mode pulls the relevant text from your collection, has an AI model synthesize an answer, and stores it in a variable everything downstream can use.

The pattern is small and reusable. Any workflow in your Spojit workspace can drop a Knowledge node at the point of need, write a natural-language prompt that references earlier steps with handlebars, and treat the answer like any other variable. Because collections are workspace-scoped, the same reference material backs many workflows at once. You can feed the synthesized answer into a Condition node for deterministic gating, or force a structured JSON shape with a Response Schema so downstream steps can read named fields.

Prerequisites

  • A persistent Knowledge collection containing the reference material you want to draw on (policies, product specs, troubleshooting guides, etc.). Create one from the Knowledge section of the sidebar and upload documents with Upload & Embed.
  • A host workflow with at least one earlier step that produces the variables your prompt will reference (an order, a request payload, a customer record).

Step 1: Identify the Enrichment Point

Open the workflow that needs enrichment. Find the step immediately before the decision or action that needs context - typically that's after a record is fetched and before a Condition, Human, or Connector step. The Knowledge node goes in between so the answer is available as a variable for everything that follows.

Step 2: Knowledge Node - Write the Query Prompt

Insert a Knowledge node and set its mode to Query. Pick your persistent collection in Collection, then write a natural-language Prompt that references earlier-step variables with handlebars so each run picks up the right context:

What are the shipping restrictions for {{ order.product_category }}
shipped to {{ order.destination_country }}? Quote the relevant rule.

Set Model to the AI model that synthesizes the answer, leave Result Count at the default of 5 (the number of document chunks retrieved before synthesis), and name the Output Variable kbContext. The variable holds the synthesized answer text.

Step 3: Force a Structured Answer with a Response Schema

If a downstream Condition node needs to read a specific field rather than parse free text, add a Response Schema in the Knowledge node. The query then returns JSON matching your schema, for example a restricted boolean and a rule string. Downstream steps reference fields directly as {{ kbContext.restricted }} and {{ kbContext.rule }} instead of scanning prose.

Step 4: Branch on the Result

You have two main consumption patterns:

  • Deterministic gating - with a Response Schema set, add a Condition node that branches on a field such as {{ kbContext.restricted }}.
  • Human judgement - route an ambiguous or empty answer to a Human node so an approver can supply the missing context. Letting the workflow proceed with an empty answer is almost always worse than asking.

On the path that needs a person, add a Human node, fill in Message referencing {{ kbContext }}, and add an Approval slot so the workflow pauses until someone approves.

Step 5: Feed the Context into the Action Step

Whatever the next step is - a Connector node that updates a record, a Send Email node that builds a customer-facing message, or a Transform node - reference the synthesized answer inline:

You are reviewing order {{ order.id }}.

Relevant policy guidance:
{{ kbContext }}

If the policy requires manual review, say so and quote the rule.

For multi-step reasoning over the answer, point a Connector node in Agent mode at this prompt so an AI agent can decide which connector tools to call.

Step 6: Log the Retrieval for Audit

For regulated or auditable workflows, write the prompt, the answer in kbContext, and the chosen branch to an audit table with the mongodb insert-documents tool or the mysql insert-rows tool. When someone asks six months later "why did we approve that?" you can replay the exact guidance that informed the decision.

Tips

  • Keep the prompt targeted - one specific question synthesizes better than a kitchen-sink prompt that tries to cover three concerns at once. Use two Knowledge nodes if you need two answers.
  • Tune Result Count - if answers miss context, raise Result Count above the default of 5 so more chunks reach the model; if answers ramble, lower it to keep the synthesis focused.
  • Cache hot lookups - if the same product category gets queried hundreds of times an hour, stash the answer with the mongodb insert-documents tool keyed on the category and read it back for a few minutes before re-querying.

Common Pitfalls

  • Quote the source, not just the verdict - for compliance-grade decisions, prompt the Knowledge node to quote the relevant rule verbatim rather than only returning a yes/no, so the answer you log is auditable.
  • Stale data in a long-running run - if the workflow pauses for a day at a Human step, the kbContext from yesterday may have been superseded. Add a second Knowledge query after the human responds when freshness matters.
  • Mismatched embedding models - a collection is locked to the embedding model chosen when it was created. Query the collection you actually embedded your documents into, or retrieval quality drops.

Testing

Take three real records that previously triggered manual escalation. Run the workflow with the Knowledge node inserted but everything downstream disabled. Inspect kbContext in the execution history for each: did it return the guidance you would have quoted by hand? Only after all three look right should you wire the downstream action step back in and let the enrichment go live. You can also ask Miraxa, the intelligent layer across your automation, why a particular run returned the answer it did.

Learn More

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.