Prompts errors
Common error signatures
Errors in this module come from invalid inputs to build_augmented_prompt. Both are ValueError:
query must be a non-empty string— raised whenqueryis an empty string or a non-string type. Check that the value passed tobuild_augmented_prompt(query=...)is a non-emptystrbefore calling the function.unknown prompt variant {...}; valid: {...}— raised when thevariantargument does not match any registered prompt variant. The error message includes both the unrecognised value you passed and the set of accepted values, so you can correct the call or register a new variant.
Where errors originate
build_augmented_prompt(query, context, variant)— validatesqueryandvariantbefore rendering; raisesValueErrorfor either input constraint listed above.join_context(hits, corpus, max_chars)— concatenatesRetrievalHitcontents into<passage>...</passage>-wrapped context strings; errors here typically indicate problems with thehitsiterable or acorpusthat does not satisfyCorpusProtocol.join_context_numbered(hits, corpus, max_chars)— same wrapping behaviour asjoin_context, but produces[P1]/[P2]-labelled passage bodies; the same iterable and corpus constraints apply.
How to diagnose
-
Read the
ValueErrormessage directly. Both validation errors inbuild_augmented_promptinclude the offending value and, for variant mismatches, the full list of valid options. You usually do not need a debugger — fix the argument shown in the message. -
Confirm
queryis a non-empty string before the call. Ifqueryis assembled dynamically (e.g. from user input or a retrieval pipeline), add an assertion or guard upstream:if not isinstance(query, str) or not query: raise ValueError("query must be provided before calling build_augmented_prompt") -
Check the
variantvalue against the valid set. When the unknown-variant error fires, the message prints both the bad value and the accepted variants. Verify that any string passed asvariantexactly matches one of those values (the comparison is case-sensitive). -
Inspect the
hitsiterable when context is empty or malformed. If the rendered prompt contains no passage content, confirm thatjoin_contextorjoin_context_numberedis receiving a non-empty iterable ofRetrievalHitobjects. An empty iterable produces an empty context string, whichbuild_augmented_promptwill silently embed — no exception is raised, but the LLM receives no grounding passages. -
Verify prompt injection defence is not corrupting passage content. The
<passage>sentinel wrapper includes an injection-defence clause. If downstream parsing breaks on the rendered prompt, check whether your hit contents themselves contain literal</passage>strings, which the module deliberately treats as documentation rather than closing tags.
Source files
src/attune_rag/prompts.py
Tags: prompts, templates, augmentation, citation