RAG Grounding
RAG grounding is a technique that anchors generated code and explanations to retrieved attune-help documentation, so every response cites real APIs, workflow names, and CLI commands rather than inventing them.
How the pieces fit together
When you invoke RagCodeGenWorkflow, it runs a two-stage pipeline:
- Retrieval. The workflow queries attune-rag to fetch relevant documentation passages. These arrive wrapped in
<passage>...</passage>tags. - Grounded generation. Those passages are injected into a citation-forced system prompt that instructs the model to reference only what the retrieved context attests — never to invent attune features — and to note the source file for any pattern it references.
The result is a WorkflowResult that carries both the generated output and its provenance.
Why grounding matters here
Without retrieval, a code-generation model can hallucinate plausible-sounding but nonexistent attune APIs. Grounding enforces faithfulness: the system prompt explicitly prohibits the model from referencing anything outside the supplied passages, and the source-file citations let you verify each claim against the real codebase.
Prompt injection hardening
Because user-supplied content arrives inside <passage> tags, the system prompt treats everything inside those tags as documentation, not as instructions. Any text inside a passage that looks like a directive — including a literal </passage> escape — is interpreted as content about that technique, not as a command to the model. This prevents retrieved content from hijacking the generation step.
RagCodeGenWorkflow at a glance
RagCodeGenWorkflow is the single entry point for RAG-grounded code generation. You construct it with keyword arguments and call execute(**kwargs) to run the full retrieve-then-generate cycle and receive a WorkflowResult.
from workflows.rag_code_gen import RagCodeGenWorkflow
workflow = RagCodeGenWorkflow(**init_kwargs)
result = workflow.execute(**run_kwargs)
Unresolved references
Auto-generated by attune-author fact-check. Review and either fix the source code, fix this doc, or add an override.
| Location | Severity | Issue |
|---|---|---|
| Line 36 (code fence) | error | from workflows.rag_code_gen import … — module not importable |