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:
| Variable | Type | Source | Description |
|---|---|---|---|
passage_id | str | Content API | Canonical passage ID (e.g., gen.1.1) |
book_title | str | Book registry | Human-readable book name |
chapter | int | Content API | Chapter number |
verse | int | Content API | Verse number |
translation_text | str | Content API | Full verse text |
witnesses | list[str] | Content API | Manuscript witness texts (optional) |
original_language_words | list[dict] | Content API | Hebrew/Greek words with glosses (optional) |
cross_references | list[str] | Content API | Related passage IDs (optional) |
topics | list[str] | Content API | Topical 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:
- Passage text — The verse(s) being explained
- Cross-references — Related passages from the graph
- Original language — Hebrew/Greek word alignments and glosses
- Topics — Topical Guide entries linked to the passage
- 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).
Related Pages
- AI Service Overview — service configuration and setup
- LLM Client Architecture — provider abstraction and caching
- Content Service > Endpoints — API used to fetch passage context