Implementation:Run llama Llama index Default Prompts
| Knowledge Sources | |
|---|---|
| Domains | Prompts, LLM, RAG |
| Last Updated | 2026-02-11 19:00 GMT |
Overview
Defines all built-in default prompt templates used throughout the LlamaIndex framework for tasks such as summarization, question answering, text-to-SQL, keyword extraction, knowledge graph triplet extraction, and document reranking.
Description
The default_prompts.py module provides a comprehensive set of pre-defined PromptTemplate instances organized by functional category:
Tree Prompts:
- DEFAULT_SUMMARY_PROMPT (type: SUMMARY) instructs the LLM to write a summary of provided context, including as many key details as possible.
- DEFAULT_INSERT_PROMPT (type: TREE_INSERT) is used during tree index construction to determine which summary node a new chunk should be inserted under.
- DEFAULT_QUERY_PROMPT (type: TREE_SELECT) asks the LLM to select the single most relevant summary from a numbered list given a query.
- DEFAULT_QUERY_PROMPT_MULTIPLE (type: TREE_SELECT_MULTIPLE) extends single selection to allow choosing up to {branching_factor} summaries ranked by relevance.
- DEFAULT_REFINE_PROMPT (type: REFINE) refines an existing answer with additional context, returning the original if the new context is not useful.
- DEFAULT_TEXT_QA_PROMPT (type: QUESTION_ANSWER) is the standard question-answering prompt: given context, answer the query without prior knowledge.
- DEFAULT_TREE_SUMMARIZE_PROMPT (type: SUMMARY) similar to QA but explicitly notes context from multiple sources.
Keyword Table Prompts:
- DEFAULT_KEYWORD_EXTRACT_TEMPLATE (type: KEYWORD_EXTRACT) extracts up to {max_keywords} keywords from text, avoiding stopwords.
- DEFAULT_QUERY_KEYWORD_EXTRACT_TEMPLATE (type: QUERY_KEYWORD_EXTRACT) extracts keywords from a question optimized for answer lookup.
Structured Store Prompts:
- DEFAULT_SCHEMA_EXTRACT_PROMPT (type: SCHEMA_EXTRACT) extracts structured fields from unstructured text given a schema definition.
- DEFAULT_TEXT_TO_SQL_PROMPT (type: TEXT_TO_SQL) generates a syntactically correct SQL query from a natural language question, following a strict Question/SQLQuery/SQLResult/Answer format.
- DEFAULT_TEXT_TO_SQL_PGVECTOR_PROMPT (type: TEXT_TO_SQL) extends text-to-SQL with pgvector-specific syntax for semantic search using the <-> nearest-neighbor operator and [query_vector] placeholder.
- DEFAULT_TABLE_CONTEXT_PROMPT (type: TABLE_CONTEXT) generates a response given table schema and context information.
- DEFAULT_REFINE_TABLE_CONTEXT_PROMPT (type: TABLE_CONTEXT) refines an existing answer about table context with new information.
Knowledge Graph Prompts:
- DEFAULT_KG_TRIPLET_EXTRACT_PROMPT (type: KNOWLEDGE_TRIPLET_EXTRACT) extracts knowledge triplets in (subject, predicate, object) form from text.
- DEFAULT_DYNAMIC_EXTRACT_PROMPT (type: KNOWLEDGE_TRIPLET_EXTRACT) extracts typed triplets with head_type and tail_type using an initial ontology, outputting JSON format.
- DEFAULT_DYNAMIC_EXTRACT_PROPS_PROMPT (type: KNOWLEDGE_TRIPLET_EXTRACT) extends dynamic extraction to include entity and relation properties.
Other Prompts:
- DEFAULT_HYDE_PROMPT (type: SUMMARY) generates hypothetical document embeddings by writing a passage to answer a question (HyDE technique).
- DEFAULT_SIMPLE_INPUT_PROMPT (type: SIMPLE_INPUT) passes the query string through directly with no additional formatting.
- DEFAULT_JSON_PATH_PROMPT (type: JSON_PATH) generates JSON Path queries from natural language given a JSON schema.
- DEFAULT_CHOICE_SELECT_PROMPT (type: CHOICE_SELECT) selects relevant documents from a numbered list and assigns relevance scores (1-10).
- STRUCTURED_CHOICE_SELECT_PROMPT (type: CHOICE_SELECT) a simplified version of choice selection without examples.
- RANKGPT_RERANK_PROMPT (type: RANKGPT_RERANK) ranks passages by relevance to a search query in descending order using bracket notation.
- DEFAULT_JSONALYZE_PROMPT (type: TEXT_TO_SQL) generates SQLite SQL queries for JSON analysis given a table name and schema.
Usage
These default prompts are used automatically throughout LlamaIndex when no custom prompts are provided. They can be overridden by passing custom PromptTemplate instances to query engines, response synthesizers, index builders, and other components. They serve as sensible defaults for common RAG, summarization, structured extraction, and knowledge graph tasks.
Code Reference
Source Location
- Repository: Run_llama_Llama_index
- File: llama-index-core/llama_index/core/prompts/default_prompts.py
- Lines: 1-545
Signature
# Key prompt template instances defined in this module:
DEFAULT_SUMMARY_PROMPT: PromptTemplate
DEFAULT_INSERT_PROMPT: PromptTemplate
DEFAULT_QUERY_PROMPT: PromptTemplate
DEFAULT_QUERY_PROMPT_MULTIPLE: PromptTemplate
DEFAULT_REFINE_PROMPT: PromptTemplate
DEFAULT_TEXT_QA_PROMPT: PromptTemplate
DEFAULT_TREE_SUMMARIZE_PROMPT: PromptTemplate
DEFAULT_KEYWORD_EXTRACT_TEMPLATE: PromptTemplate
DEFAULT_QUERY_KEYWORD_EXTRACT_TEMPLATE: PromptTemplate
DEFAULT_SCHEMA_EXTRACT_PROMPT: PromptTemplate
DEFAULT_TEXT_TO_SQL_PROMPT: PromptTemplate
DEFAULT_TEXT_TO_SQL_PGVECTOR_PROMPT: PromptTemplate
DEFAULT_TABLE_CONTEXT_PROMPT: PromptTemplate
DEFAULT_REFINE_TABLE_CONTEXT_PROMPT: PromptTemplate
DEFAULT_KG_TRIPLET_EXTRACT_PROMPT: PromptTemplate
DEFAULT_DYNAMIC_EXTRACT_PROMPT: PromptTemplate
DEFAULT_DYNAMIC_EXTRACT_PROPS_PROMPT: PromptTemplate
DEFAULT_HYDE_PROMPT: PromptTemplate
DEFAULT_SIMPLE_INPUT_PROMPT: PromptTemplate
DEFAULT_JSON_PATH_PROMPT: PromptTemplate
DEFAULT_CHOICE_SELECT_PROMPT: PromptTemplate
STRUCTURED_CHOICE_SELECT_PROMPT: PromptTemplate
RANKGPT_RERANK_PROMPT: PromptTemplate
DEFAULT_JSONALYZE_PROMPT: PromptTemplate
Import
from llama_index.core.prompts.default_prompts import DEFAULT_TEXT_QA_PROMPT
from llama_index.core.prompts.default_prompts import DEFAULT_REFINE_PROMPT
from llama_index.core.prompts.default_prompts import DEFAULT_SUMMARY_PROMPT
from llama_index.core.prompts.default_prompts import DEFAULT_TEXT_TO_SQL_PROMPT
from llama_index.core.prompts.default_prompts import DEFAULT_KG_TRIPLET_EXTRACT_PROMPT
I/O Contract
Inputs (Common Template Variables)
| Name | Type | Required | Description |
|---|---|---|---|
| context_str | str | Varies | Context text provided from retrieval results |
| query_str | str | Varies | The user's query or question |
| existing_answer | str | No | An existing answer to be refined (used in REFINE prompts) |
| context_msg | str | No | Additional context message (used in refine templates) |
| num_chunks | str | No | Number of summary chunks in a list (used in tree prompts) |
| context_list | str | No | Numbered list of context summaries (used in tree prompts) |
| schema | str | No | Database or JSON schema (used in structured prompts) |
| dialect | str | No | SQL dialect name (used in text-to-SQL prompts) |
| max_keywords | str | No | Maximum number of keywords to extract |
| max_knowledge_triplets | str | No | Maximum number of knowledge graph triplets to extract |
| text | str | No | Input text for extraction tasks |
Outputs
| Name | Type | Description |
|---|---|---|
| format() | str | The fully rendered prompt string with all template variables filled in |
Usage Examples
Basic Usage with DEFAULT_TEXT_QA_PROMPT
from llama_index.core.prompts.default_prompts import DEFAULT_TEXT_QA_PROMPT
prompt_str = DEFAULT_TEXT_QA_PROMPT.format(
context_str="LlamaIndex is a data framework for LLM applications.",
query_str="What is LlamaIndex?"
)
print(prompt_str)
# Output:
# Context information is below.
# ---------------------
# LlamaIndex is a data framework for LLM applications.
# ---------------------
# Given the context information and not prior knowledge, answer the query.
# Query: What is LlamaIndex?
# Answer:
Overriding Default Prompts in a Query Engine
from llama_index.core.prompts.base import PromptTemplate
from llama_index.core import VectorStoreIndex
custom_qa_prompt = PromptTemplate(
"Based on the following context:\n{context_str}\n"
"Please answer concisely: {query_str}\n"
)
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(
text_qa_template=custom_qa_prompt,
)
Using Text-to-SQL Prompt
from llama_index.core.prompts.default_prompts import DEFAULT_TEXT_TO_SQL_PROMPT
prompt_str = DEFAULT_TEXT_TO_SQL_PROMPT.format(
dialect="PostgreSQL",
schema="CREATE TABLE users (id INT, name TEXT, email TEXT);",
query_str="How many users are there?"
)