Skip to main content

Prompt Templates

The AI service uses Jinja2 templates (.j2 files) to construct prompts for LLM interactions. Templates receive structured context from the GospeLib knowledge graph and produce scholarly, citational responses.

Template Location

services/ai/src/gospelib_ai/llm/prompts/
├── explain_passage.j2
├── study_questions.j2
├── cross_references.j2
└── base_system.j2

Example: Passage Explanation

{# services/ai/src/gospelib_ai/llm/prompts/explain_passage.j2 #}
You are a knowledgeable Latter-day Saint scripture scholar with expertise in
the original Hebrew, Greek, and Aramaic texts, LDS temple theology, and the
relationship between canonical scripture and ancient religious texts such as
the Dead Sea Scrolls, 1 Enoch, and Jubilees.

Your explanations are faithful to LDS doctrine while being scholarly and precise.
You cite relevant cross-references, original language insights, and LDS scholarly
sources (Hugh Nibley, Jeffrey Bradshaw, John W. Welch, BYU New Testament Commentary).

Context from the GospeLib knowledge graph:
- Passage: {{ passage_id }} ({{ book_title }} {{ chapter }}:{{ verse }})
- Translation: {{ translation_text }}
{%- if witnesses %}
- Manuscript witnesses: {{ witnesses | join(", ") }}
{%- endif %}
{%- if original_language_words %}
- Original language: {{ original_language_words | join(", ", attribute="gloss") }}
{%- endif %}
{%- if cross_references %}
- Related passages: {{ cross_references | join(", ") }}
{%- endif %}
{%- if topics %}
- Topical Guide topics: {{ topics | join(", ") }}
{%- endif %}

Explain this passage in 2–4 paragraphs. Be specific. Cite sources.

Template Variables

Each template receives a context dictionary with data pulled from the content service:

VariableTypeSourceDescription
passage_idstrContent APICanonical passage ID (e.g., gen.1.1)
book_titlestrBook registryHuman-readable book name
chapterintContent APIChapter number
verseintContent APIVerse number
translation_textstrContent APIFull verse text
witnesseslist[str]Content APIManuscript witness texts (optional)
original_language_wordslist[dict]Content APIHebrew/Greek words with glosses (optional)
cross_referenceslist[str]Content APIRelated passage IDs (optional)
topicslist[str]Content APITopical Guide topic names (optional)

Template Rendering

from jinja2 import Environment, PackageLoader

env = Environment(
loader=PackageLoader("gospelib_ai", "llm/prompts"),
autoescape=False, # Prompts are plain text, not HTML
)

def render_prompt(template_name: str, context: dict) -> str:
template = env.get_template(template_name)
return template.render(**context)

# Usage
system_prompt = render_prompt("explain_passage.j2", {
"passage_id": "gen.1.1",
"book_title": "Genesis",
"chapter": 1,
"verse": 1,
"translation_text": "In the beginning God created the heaven and the earth.",
"cross_references": ["john.1.1", "abr.4.1"],
"topics": ["Creation", "God the Father"],
})

Prompt Design Guidelines

Scholarly Tone

All prompts instruct the LLM to be scholarly and citational:

  • Cite specific LDS scholars (Hugh Nibley, John W. Welch, Jeffrey Bradshaw)
  • Reference original language when relevant (Hebrew, Greek, Aramaic)
  • Connect to ancient texts (Dead Sea Scrolls, 1 Enoch, Jubilees)
  • Remain faithful to LDS doctrine while being academically rigorous

Context Enrichment

Before calling the LLM, the AI service fetches passage context from the Content service:

  1. Passage text — The verse(s) being explained
  2. Cross-references — Related passages from the graph
  3. Original language — Hebrew/Greek word alignments and glosses
  4. Topics — Topical Guide entries linked to the passage
  5. Witnesses — Manuscript variants (Book of Mormon only)

This context is injected into the template, giving the LLM specific data to work with instead of relying on its general knowledge.

Conditional Sections

Templates use Jinja2 conditionals to include only available context:

{%- if original_language_words %}
- Original language: {{ original_language_words | join(", ", attribute="gloss") }}
{%- endif %}

This prevents empty sections from appearing in prompts when data isn't available (e.g., no Hebrew/Greek for Book of Mormon passages).