Comparison: join_context vs join_context_numbered

Overview

Both functions assemble retrieved passages into a context string that build_augmented_prompt can inject into an LLM prompt. They differ in how they label passages and whether they defend against prompt injection.

Capability join_context join_context_numbered
Passage wrapping <passage>…</passage> <passage>…</passage>
Passage labels None [P1], [P2], …
Injection-defense clause Yes (_INJECTION_DEFENSE_CLAUSE prepended) Yes (_INJECTION_DEFENSE_CLAUSE prepended)
Suitable for citation-style prompts No — no stable label for the model to cite Yes — labels give the model a citation target
Output when model must explain its sources Harder; model cannot reference a specific passage Straightforward; model can write "see [P2]"
Character budget Configurable via max_chars Configurable via max_chars
Accepts optional CorpusProtocol Yes Yes

Both functions wrap every passage in <passage>…</passage> tags and prepend _INJECTION_DEFENSE_CLAUSE, which instructs the model to treat content inside those tags as documentation rather than executable instructions — even if that content contains directives or attempts to close the wrapping tag prematurely.

When to use join_context

Use join_context when:

When to use join_context_numbered

Use join_context_numbered when:

When to use neither directly

Recommendation

Prefer join_context_numbered when in doubt. The [P1]/[P2] labels cost nothing at assembly time and give the model — and any downstream parser — a stable handle on each passage. Switch to join_context only when you have a specific reason to omit labels, such as a prompt variant that treats context as a single undifferentiated block.

Source files

Tags: prompts, templates, augmentation, citation