prompt.py — langchain Source File
Architecture documentation for prompt.py, a python file in the langchain codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 394b7492_3f33_6907_fb90_d04bd6c38e88["prompt.py"] f9729912_0834_0496_61f4_d5418318c60e["langchain_core.output_parsers.list"] 394b7492_3f33_6907_fb90_d04bd6c38e88 --> f9729912_0834_0496_61f4_d5418318c60e 4b3dcc0f_d872_0044_39ec_2d289f87f9e6["langchain_core.prompts.prompt"] 394b7492_3f33_6907_fb90_d04bd6c38e88 --> 4b3dcc0f_d872_0044_39ec_2d289f87f9e6 style 394b7492_3f33_6907_fb90_d04bd6c38e88 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from langchain_core.output_parsers.list import CommaSeparatedListOutputParser
from langchain_core.prompts.prompt import PromptTemplate
PROMPT_SUFFIX = """Only use the following tables:
{table_info}
Question: {input}"""
_DEFAULT_TEMPLATE = """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. Unless the user specifies in his question a specific number of examples he wishes to obtain, always limit your query to at most {top_k} results. 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. Also, pay attention to which column is in which table.
Use the following format:
Question: Question here
SQLQuery: SQL Query to run
SQLResult: Result of the SQLQuery
Answer: Final answer here
""" # noqa: E501
PROMPT = PromptTemplate(
input_variables=["input", "table_info", "dialect", "top_k"],
template=_DEFAULT_TEMPLATE + PROMPT_SUFFIX,
)
_DECIDER_TEMPLATE = """Given the below input question and list of potential tables, output a comma separated list of the table names that may be necessary to answer this question.
Question: {query}
Table Names: {table_names}
Relevant Table Names:""" # noqa: E501
DECIDER_PROMPT = PromptTemplate(
input_variables=["query", "table_names"],
template=_DECIDER_TEMPLATE,
output_parser=CommaSeparatedListOutputParser(),
)
_cratedb_prompt = """You are a CrateDB expert. Given an input question, first create a syntactically correct CrateDB query to run, then look at the results of the query and return the answer to the input question.
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per CrateDB. You can order the results to return the most informative data in the database.
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
Pay attention to use CURRENT_DATE function to get the current date, if the question involves "today".
Use the following format:
Question: Question here
SQLQuery: SQL Query to run
SQLResult: Result of the SQLQuery
Answer: Final answer here
""" # noqa: E501
CRATEDB_PROMPT = PromptTemplate(
input_variables=["input", "table_info", "top_k"],
template=_cratedb_prompt + PROMPT_SUFFIX,
// ... (223 more lines)
Dependencies
- langchain_core.output_parsers.list
- langchain_core.prompts.prompt
Source
Frequently Asked Questions
What does prompt.py do?
prompt.py is a source file in the langchain codebase, written in python.
What does prompt.py depend on?
prompt.py imports 2 module(s): langchain_core.output_parsers.list, langchain_core.prompts.prompt.
Where is prompt.py in the architecture?
prompt.py is located at libs/langchain/langchain_classic/chains/sql_database/prompt.py (directory: libs/langchain/langchain_classic/chains/sql_database).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free