LlamaIndex Default Prompt Library Official
This system prompt was officially published by LlamaIndex. Source link below.
The original query is as follows: {query_str}
We have provided an existing answer: {existing_answer}
We have the opportunity to refine the existing answer (only if needed) with some more context below.
------------
{context_msg}
------------
Given the new context, refine the original answer to better answer the query. If the context isn't useful, return the original answer.
Refined Answer:
Context information is below.
---------------------
{context_str}
---------------------
Given the context information and not prior knowledge, answer the query.
Query: {query_str}
Answer:
Given an input question, first create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer. You can order the results by a relevant column to return the most interesting examples in the database.
Never query for all the columns from a specific table, only ask for a few relevant columns given the question.
Pay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Pay attention to which column is in which table. Also, qualify column names with the table name when needed. You are required to use the following format, each taking one line:
Question: Question here
SQLQuery: SQL Query to run
SQLResult: Result of the SQLQuery
Answer: Final answer here
Only use tables listed below.
{schema}
Question: {query_str}
SQLQuery:
Extract up to {max_knowledge_triplets} knowledge triplets from the given text. Each triplet should be in the form of (head, relation, tail) with their respective types.
---------------------
INITIAL ONTOLOGY:
Entity Types: {allowed_entity_types}
Relation Types: {allowed_relation_types}
Use these types as a starting point, but introduce new types if necessary based on the context.
GUIDELINES:
- Output in JSON format: [{{'head': '', 'head_type': '', 'relation': '', 'tail': '', 'tail_type': ''}}]
- Use the most complete form for entities (e.g., 'United States of America' instead of 'USA')
- Keep entities concise (3-5 words max)
- Break down complex phrases into multiple triplets
- Ensure the knowledge graph is coherent and easily understandable
---------------------
EXAMPLE:
Text: Tim Cook, CEO of Apple Inc., announced the new Apple Watch that monitors heart health. UC Berkeley researchers studied the benefits of apples.
Output:
[{{'head': 'Tim Cook', 'head_type': 'PERSON', 'relation': 'CEO_OF', 'tail': 'Apple Inc.', 'tail_type': 'COMPANY'}},
{{'head': 'Apple Inc.', 'head_type': 'COMPANY', 'relation': 'PRODUCES', 'tail': 'Apple Watch', 'tail_type': 'PRODUCT'}},
{{'head': 'Apple Watch', 'head_type': 'PRODUCT', 'relation': 'MONITORS', 'tail': 'heart health', 'tail_type': 'HEALTH_METRIC'}},
{{'head': 'UC Berkeley', 'head_type': 'UNIVERSITY', 'relation': 'STUDIES', 'tail': 'benefits of apples', 'tail_type': 'RESEARCH_TOPIC'}}]
---------------------
Text: {text}
Output:
Source: LlamaIndex official open-source repo (selected default templates) · excerpt shown — full document at the source
What's worth stealing from this prompt
- Grounding is repeated as an explicit instruction hierarchy: use the supplied context and not prior knowledge for QA, tree summaries, and selection tasks.
- The refine template has a no-op outcome — return the original answer when new context is not useful — which prevents refinement from becoming mandatory rewriting.
- Text-to-SQL constrains both schema and output: only listed tables and visible columns, qualified names where needed, and a fixed Question/SQLQuery/SQLResult/Answer sequence.
- Knowledge-graph extraction provides an initial ontology, typed triples, compact entities, and a full example, combining controlled structure with permission to extend types.
Apply the patterns
Curated prompts from our own library that use similar techniques:
More reverse-engineered prompts
Fair use: these prompt texts are reproduced for commentary, analysis, and educational purposes. All rights belong to their respective owners; if you are a rights holder and want an entry removed, contact us and we will take it down promptly.