property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.SimpleSequentialChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, chains, strip_outputs=False, input_key='input', output_key='output')[source]
Bases: langchain.chains.base.Chain
Simple chain where the outputs of one step feed directly into next.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
chains (List[langchain.chains.base.Chain]) –
strip_outputs (bool) –
input_key (str) –
output_key (str) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute chains: List[langchain.chains.base.Chain] [Required]
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.


them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute strip_outputs: bool = False
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters


Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters


Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.TransformChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, input_variables, output_variables, transform)[source]
Bases: langchain.chains.base.Chain
Chain transform chain output.
Example
from langchain import TransformChain
transform_chain = TransformChain(input_variables=["text"],
 output_variables["entities"], transform=func())
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –


verbose (bool) –
tags (Optional[List[str]]) –
input_variables (List[str]) –
output_variables (List[str]) –
transform (Callable[[Dict[str, str]], Dict[str, str]]) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute input_variables: List[str] [Required]
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute output_variables: List[str] [Required]
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute transform: Callable[[Dict[str, str]], Dict[str, str]] [Required]
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.


will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
dict(**kwargs)


kwargs (Any) –
Return type
str
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.


property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.VectorDBQA(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, combine_documents_chain, input_key='query', output_key='result', return_source_documents=False, vectorstore, k=4, search_type='similarity', search_kwargs=None)[source]
Bases: langchain.chains.retrieval_qa.base.BaseRetrievalQA
Chain for question-answering against a vector database.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
combine_documents_chain (langchain.chains.combine_documents.base.BaseCombineDocumentsChain) –
input_key (str) –
output_key (str) –
return_source_documents (bool) –
vectorstore (langchain.vectorstores.base.VectorStore) –
k (int) –
search_type (str) –
search_kwargs (Dict[str, Any]) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None


Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute combine_documents_chain: BaseCombineDocumentsChain [Required]
Chain to use to combine the documents.
attribute k: int = 4
Number of documents to query for.
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute return_source_documents: bool = False
Return the source documents.
attribute search_kwargs: Dict[str, Any] [Optional]
Extra search args.
attribute search_type: str = 'similarity'
Search type to use over vectorstore. similarity or mmr.
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute vectorstore: VectorStore [Required]
Vector Database to connect to.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs


Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –


tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
classmethod from_chain_type(llm, chain_type='stuff', chain_type_kwargs=None, **kwargs)
Load chain from chain type.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
chain_type (str) –
chain_type_kwargs (Optional[dict]) –
kwargs (Any) –
Return type
langchain.chains.retrieval_qa.base.BaseRetrievalQA
classmethod from_llm(llm, prompt=None, **kwargs)
Initialize from LLM.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
prompt (Optional[langchain.prompts.prompt.PromptTemplate]) –
kwargs (Any) –
Return type
langchain.chains.retrieval_qa.base.BaseRetrievalQA
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –


tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.VectorDBQAWithSourcesChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, combine_documents_chain, question_key='question', input_docs_key='docs', answer_key='answer', sources_answer_key='sources', return_source_documents=False, vectorstore, k=4, reduce_k_below_max_tokens=False, max_tokens_limit=3375, search_kwargs=None)[source]
Bases: langchain.chains.qa_with_sources.base.BaseQAWithSourcesChain
Question-answering with sources over a vector database.
Parameters


Question-answering with sources over a vector database.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
combine_documents_chain (langchain.chains.combine_documents.base.BaseCombineDocumentsChain) –
question_key (str) –
input_docs_key (str) –
answer_key (str) –
sources_answer_key (str) –
return_source_documents (bool) –
vectorstore (langchain.vectorstores.base.VectorStore) –
k (int) –
reduce_k_below_max_tokens (bool) –
max_tokens_limit (int) –
search_kwargs (Dict[str, Any]) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute combine_documents_chain: BaseCombineDocumentsChain [Required]
Chain to use to combine documents.
attribute k: int = 4
Number of results to return from store
attribute max_tokens_limit: int = 3375
Restrict the docs to return from store based on tokens,
enforced only for StuffDocumentChain and if reduce_k_below_max_tokens is to true


enforced only for StuffDocumentChain and if reduce_k_below_max_tokens is to true
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute reduce_k_below_max_tokens: bool = False
Reduce the number of results to return from store based on tokens limit
attribute return_source_documents: bool = False
Return the source documents.
attribute search_kwargs: Dict[str, Any] [Optional]
Extra search args.
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute vectorstore: langchain.vectorstores.base.VectorStore [Required]
Vector Database to connect to.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the


return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
classmethod from_chain_type(llm, chain_type='stuff', chain_type_kwargs=None, **kwargs)
Load chain from chain type.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
chain_type (str) –


chain_type (str) –
chain_type_kwargs (Optional[dict]) –
kwargs (Any) –
Return type
langchain.chains.qa_with_sources.base.BaseQAWithSourcesChain


classmethod from_llm(llm, document_prompt=PromptTemplate(input_variables=['page_content', 'source'], output_parser=None, partial_variables={}, template='Content: {page_content}\nSource: {source}', template_format='f-string', validate_template=True), question_prompt=PromptTemplate(input_variables=['context', 'question'], output_parser=None, partial_variables={}, template='Use the following portion of a long document to see if any of the text is relevant to answer the question. \nReturn any relevant text verbatim.\n{context}\nQuestion: {question}\nRelevant text, if any:', template_format='f-string', validate_template=True), combine_prompt=PromptTemplate(input_variables=['summaries', 'question'], output_parser=None, partial_variables={}, template='Given the following extracted parts of a long document and a question, create a final answer with references ("SOURCES"). \nIf you don\'t know the answer, just say that you don\'t know. Don\'t try to make up an answer.\nALWAYS return a "SOURCES" part in your answer.\n\nQUESTION: Which state/country\'s law governs the interpretation of the contract?\n=========\nContent: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in  relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an  injunction or other relief to protect its Intellectual Property Rights.\nSource: 28-pl\nContent: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other)  right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation  in force of the remainder of the term (if


of this Agreement shall not affect the continuation  in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any  kind between the parties.\n\n11.9 No Third-Party Beneficiaries.\nSource: 30-pl\nContent: (b) if Google believes, in good faith, that the Distributor has violated or caused Google to violate any Anti-Bribery Laws (as  defined in Clause 8.5) or that such a violation is reasonably likely to occur,\nSource: 4-pl\n=========\nFINAL ANSWER: This Agreement is governed by English law.\nSOURCES: 28-pl\n\nQUESTION: What did the president say about Michael Jackson?\n=========\nContent: Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans.  \n\nLast year COVID-19 kept us apart. This year we are finally together again. \n\nTonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \n\nWith a duty to one another to the American people to the Constitution. \n\nAnd with an unwavering resolve that freedom will always triumph over tyranny. \n\nSix days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \n\nHe thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \n\nHe met the Ukrainian people. \n\nFrom President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n\nGroups of citizens


their fearlessness, their courage, their determination, inspires the world. \n\nGroups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland.\nSource: 0-pl\nContent: And we won’t stop. \n\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \n\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease.  \n\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans.  \n\nWe can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together. \n\nI recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera. \n\nThey were responding to a 9-1-1 call when a man shot and killed them with a stolen gun. \n\nOfficer Mora was 27 years old. \n\nOfficer Rivera was 22. \n\nBoth Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers. \n\nI spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves.\nSource: 24-pl\nContent: And a proud Ukrainian people, who have known 30 years  of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards.  \n\nTo all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around


you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world. \n\nAnd I’m taking robust action to make sure the pain of our sanctions  is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \n\nTonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world.  \n\nAmerica will lead that effort, releasing 30 Million barrels from our own Strategic Petroleum Reserve. And we stand ready to do more if necessary, unified with our allies.  \n\nThese steps will help blunt gas prices here at home. And I know the news about what’s happening can seem alarming. \n\nBut I want you to know that we are going to be okay.\nSource: 5-pl\nContent: More support for patients and families. \n\nTo get there, I call on Congress to fund ARPA-H, the Advanced Research Projects Agency for Health. \n\nIt’s based on DARPA—the Defense Department project that led to the Internet, GPS, and so much more.  \n\nARPA-H will have a singular purpose—to drive breakthroughs in cancer, Alzheimer’s, diabetes, and more. \n\nA unity agenda for the nation. \n\nWe can do this. \n\nMy fellow Americans—tonight , we have gathered in a sacred space—the citadel of our democracy. \n\nIn this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \n\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror. \n\nAnd built the strongest, freest, and most prosperous nation the world has ever known. \n\nNow is the hour. \n\nOur moment of responsibility. \n\nOur


\n\nNow is the hour. \n\nOur moment of responsibility. \n\nOur test of resolve and conscience, of history itself. \n\nIt is in this moment that our character is formed. Our purpose is found. Our future is forged. \n\nWell I know this nation.\nSource: 34-pl\n=========\nFINAL ANSWER: The president did not mention Michael Jackson.\nSOURCES:\n\nQUESTION: {question}\n=========\n{summaries}\n=========\nFINAL ANSWER:', template_format='f-string', validate_template=True), **kwargs)


Construct the chain from an LLM.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
document_prompt (langchain.prompts.base.BasePromptTemplate) –
question_prompt (langchain.prompts.base.BasePromptTemplate) –
combine_prompt (langchain.prompts.base.BasePromptTemplate) –
kwargs (Any) –
Return type
langchain.chains.qa_with_sources.base.BaseQAWithSourcesChain
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented


Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
langchain.chains.create_extraction_chain(schema, llm)[source]
Creates a chain that extracts information from a passage.
Parameters
schema (dict) – The schema of the entities to extract.
llm (langchain.base_language.BaseLanguageModel) – The language model to use.
Returns
Chain that can be used to extract information from a passage.
Return type
langchain.chains.base.Chain
langchain.chains.create_extraction_chain_pydantic(pydantic_schema, llm)[source]
Creates a chain that extracts information from a passage using pydantic schema.
Parameters
pydantic_schema (Any) – The pydantic schema of the entities to extract.
llm (langchain.base_language.BaseLanguageModel) – The language model to use.
Returns
Chain that can be used to extract information from a passage.
Return type
langchain.chains.base.Chain
langchain.chains.create_tagging_chain(schema, llm)[source]
Creates a chain that extracts information from a passage.
Parameters
schema (dict) – The schema of the entities to extract.


Parameters
schema (dict) – The schema of the entities to extract.
llm (langchain.base_language.BaseLanguageModel) – The language model to use.
Returns
Chain (LLMChain) that can be used to extract information from a passage.
Return type
langchain.chains.base.Chain
langchain.chains.create_tagging_chain_pydantic(pydantic_schema, llm)[source]
Creates a chain that extracts information from a passage.
Parameters
pydantic_schema (Any) – The pydantic schema of the entities to extract.
llm (langchain.base_language.BaseLanguageModel) – The language model to use.
Returns
Chain (LLMChain) that can be used to extract information from a passage.
Return type
langchain.chains.base.Chain
langchain.chains.load_chain(path, **kwargs)[source]
Unified method for loading a chain from LangChainHub or local fs.
Parameters
path (Union[str, pathlib.Path]) –
kwargs (Any) –
Return type
langchain.chains.base.Chain
langchain.chains.create_citation_fuzzy_match_chain(llm)[source]
Create a citation fuzzy match chain.
Parameters
llm (langchain.base_language.BaseLanguageModel) – Language model to use for the chain.
Returns
Chain (LLMChain) that can be used to answer questions with citations.
Return type
langchain.chains.llm.LLMChain
langchain.chains.create_qa_with_structure_chain(llm, schema, output_parser='base', prompt=None)[source]
Create a question answering chain that returns an answer with sources.
Parameters
llm (langchain.base_language.BaseLanguageModel) – Language model to use for the chain.


schema (Union[dict, Type[pydantic.main.BaseModel]]) – Pydantic schema to use for the output.
output_parser (str) – Output parser to use. Should be one of pydantic or base.
Default to base.
prompt (Optional[Union[langchain.prompts.prompt.PromptTemplate, langchain.prompts.chat.ChatPromptTemplate]]) – Optional prompt to use for the chain.
Return type
langchain.chains.llm.LLMChain
Returns:
langchain.chains.create_qa_with_sources_chain(llm, **kwargs)[source]
Create a question answering chain that returns an answer with sources.
Parameters
llm (langchain.base_language.BaseLanguageModel) – Language model to use for the chain.
**kwargs – Keyword arguments to pass to create_qa_with_structure_chain.
kwargs (Any) –
Returns
Chain (LLMChain) that can be used to answer questions with citations.
Return type
langchain.chains.llm.LLMChain
class langchain.chains.StuffDocumentsChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, input_key='input_documents', output_key='output_text', llm_chain, document_prompt=None, document_variable_name, document_separator='\n\n')[source]
Bases: langchain.chains.combine_documents.base.BaseCombineDocumentsChain
Chain that combines documents by stuffing into context.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
input_key (str) –
output_key (str) –


input_key (str) –
output_key (str) –
llm_chain (langchain.chains.llm.LLMChain) –
document_prompt (langchain.prompts.base.BasePromptTemplate) –
document_variable_name (str) –
document_separator (str) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute document_prompt: langchain.prompts.base.BasePromptTemplate [Optional]
Prompt to use to format each document.
attribute document_separator: str = '\n\n'
The string with which to join the formatted documents
attribute document_variable_name: str [Required]
The variable name in the llm_chain to put the documents in.
If only one variable in the llm_chain, this need not be provided.
attribute llm_chain: langchain.chains.llm.LLMChain [Required]
LLM wrapper to use after formatting documents.
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute tags: Optional[List[str]] = None


for the full catalog.
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
async acombine_docs(docs, callbacks=None, **kwargs)[source]
Stuff all documents into one prompt and pass to LLM.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –


kwargs (Any) –
Return type
Tuple[str, dict]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
combine_docs(docs, callbacks=None, **kwargs)[source]
Stuff all documents into one prompt and pass to LLM.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]


return_only_outputs (bool) –
Return type
Dict[str, str]
prompt_length(docs, **kwargs)[source]
Get the prompt length by formatting the prompt.
Parameters
docs (List[langchain.schema.Document]) –
kwargs (Any) –
Return type
Optional[int]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool


property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.MapRerankDocumentsChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, input_key='input_documents', output_key='output_text', llm_chain, document_variable_name, rank_key, answer_key, metadata_keys=None, return_intermediate_steps=False)[source]
Bases: langchain.chains.combine_documents.base.BaseCombineDocumentsChain
Combining documents by mapping a chain over them, then reranking results.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
input_key (str) –
output_key (str) –
llm_chain (langchain.chains.llm.LLMChain) –
document_variable_name (str) –
rank_key (str) –
answer_key (str) –
metadata_keys (Optional[List[str]]) –
return_intermediate_steps (bool) –
Return type
None
attribute answer_key: str [Required]
Key in output of llm_chain to return as answer.
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.


Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute document_variable_name: str [Required]
The variable name in the llm_chain to put the documents in.
If only one variable in the llm_chain, this need not be provided.
attribute llm_chain: LLMChain [Required]
Chain to apply to each document individually.
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute metadata_keys: Optional[List[str]] = None
attribute rank_key: str [Required]
Key in output of llm_chain to rank on.
attribute return_intermediate_steps: bool = False
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.


only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
async acombine_docs(docs, callbacks=None, **kwargs)[source]
Combine documents in a map rerank manner.
Combine by mapping first chain over all documents, then reranking the results.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –


tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
combine_docs(docs, callbacks=None, **kwargs)[source]
Combine documents in a map rerank manner.
Combine by mapping first chain over all documents, then reranking the results.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
prompt_length(docs, **kwargs)
Return the prompt length given the documents passed in.
Returns None if the method does not depend on the prompt length.
Parameters
docs (List[langchain.schema.Document]) –
kwargs (Any) –
Return type
Optional[int]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str


kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.MapReduceDocumentsChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, input_key='input_documents', output_key='output_text', llm_chain, combine_document_chain, collapse_document_chain=None, document_variable_name, return_intermediate_steps=False)[source]
Bases: langchain.chains.combine_documents.base.BaseCombineDocumentsChain
Combining documents by mapping a chain over them, then combining results.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –


callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
input_key (str) –
output_key (str) –
llm_chain (langchain.chains.llm.LLMChain) –
combine_document_chain (langchain.chains.combine_documents.base.BaseCombineDocumentsChain) –
collapse_document_chain (Optional[langchain.chains.combine_documents.base.BaseCombineDocumentsChain]) –
document_variable_name (str) –
return_intermediate_steps (bool) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute collapse_document_chain: Optional[BaseCombineDocumentsChain] = None
Chain to use to collapse intermediary results if needed.
If None, will use the combine_document_chain.
attribute combine_document_chain: BaseCombineDocumentsChain [Required]
Chain to use to combine results of applying llm_chain to documents.
attribute document_variable_name: str [Required]
The variable name in the llm_chain to put the documents in.
If only one variable in the llm_chain, this need not be provided.
attribute llm_chain: LLMChain [Required]
Chain to apply to each document individually.
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start


Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
attribute return_intermediate_steps: bool = False
Return the results of the map steps in the output.
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults


include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]
async acombine_docs(docs, callbacks=None, **kwargs)[source]
Combine documents in a map reduce manner.
Combine by mapping first chain over all documents, then reducing the results.
This reducing can be done recursively if needed (if there are many documents).
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
combine_docs(docs, token_max=3000, callbacks=None, **kwargs)[source]
Combine documents in a map reduce manner.
Combine by mapping first chain over all documents, then reducing the results.
This reducing can be done recursively if needed (if there are many documents).
Parameters
docs (List[langchain.schema.Document]) –
token_max (int) –


docs (List[langchain.schema.Document]) –
token_max (int) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
prompt_length(docs, **kwargs)
Return the prompt length given the documents passed in.
Returns None if the method does not depend on the prompt length.
Parameters
docs (List[langchain.schema.Document]) –
kwargs (Any) –
Return type
Optional[int]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)


Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.chains.RefineDocumentsChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, input_key='input_documents', output_key='output_text', initial_llm_chain, refine_llm_chain, document_variable_name, initial_response_name, document_prompt=None, return_intermediate_steps=False)[source]
Bases: langchain.chains.combine_documents.base.BaseCombineDocumentsChain
Combine documents by doing a first pass and then refining on more documents.
Parameters
memory (Optional[langchain.schema.BaseMemory]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
tags (Optional[List[str]]) –
input_key (str) –
output_key (str) –


input_key (str) –
output_key (str) –
initial_llm_chain (langchain.chains.llm.LLMChain) –
refine_llm_chain (langchain.chains.llm.LLMChain) –
document_variable_name (str) –
initial_response_name (str) –
document_prompt (langchain.prompts.base.BasePromptTemplate) –
return_intermediate_steps (bool) –
Return type
None
attribute callback_manager: Optional[BaseCallbackManager] = None
Deprecated, use callbacks instead.
attribute callbacks: Callbacks = None
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
attribute document_prompt: BasePromptTemplate [Optional]
Prompt to use to format each document.
attribute document_variable_name: str [Required]
The variable name in the initial_llm_chain to put the documents in.
If only one variable in the initial_llm_chain, this need not be provided.
attribute initial_llm_chain: LLMChain [Required]
LLM chain to use on initial document.
attribute initial_response_name: str [Required]
The variable name to format the initial response in when refining.
attribute memory: Optional[BaseMemory] = None
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs


There are many different types of memory - please see memory docs
for the full catalog.
attribute refine_llm_chain: LLMChain [Required]
LLM chain to use when refining.
attribute return_intermediate_steps: bool = False
Return the results of the refine steps in the output.
attribute tags: Optional[List[str]] = None
Optional list of tags associated with the chain. Defaults to None
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
attribute verbose: bool [Optional]
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to langchain.verbose value.
async acall(inputs, return_only_outputs=False, callbacks=None, *, tags=None, include_run_info=False)
Run the logic of this chain and add to output if desired.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param.
return_only_outputs (bool) – boolean for whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to use for this chain run. If not provided, will
use the callbacks provided to the chain.
include_run_info (bool) – Whether to include run info in the response. Defaults
to False.
tags (Optional[List[str]]) –
Return type
Dict[str, Any]


tags (Optional[List[str]]) –
Return type
Dict[str, Any]
async acombine_docs(docs, callbacks=None, **kwargs)[source]
Combine by mapping first chain over all, then stuffing into final chain.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
apply(input_list, callbacks=None)
Call the chain on all inputs in the list.
Parameters
input_list (List[Dict[str, Any]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
Return type
List[Dict[str, str]]
async arun(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
combine_docs(docs, callbacks=None, **kwargs)[source]
Combine by mapping first chain over all, then stuffing into final chain.
Parameters
docs (List[langchain.schema.Document]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
Tuple[str, dict]
dict(**kwargs)
Return dictionary representation of chain.
Parameters
kwargs (Any) –
Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters


Return type
Dict
prep_inputs(inputs)
Validate and prep inputs.
Parameters
inputs (Union[Dict[str, Any], Any]) –
Return type
Dict[str, str]
prep_outputs(inputs, outputs, return_only_outputs=False)
Validate and prep outputs.
Parameters
inputs (Dict[str, str]) –
outputs (Dict[str, str]) –
return_only_outputs (bool) –
Return type
Dict[str, str]
prompt_length(docs, **kwargs)
Return the prompt length given the documents passed in.
Returns None if the method does not depend on the prompt length.
Parameters
docs (List[langchain.schema.Document]) –
kwargs (Any) –
Return type
Optional[int]
run(*args, callbacks=None, tags=None, **kwargs)
Run the chain as text in, text out or multiple variables, text out.
Parameters
args (Any) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
str
save(file_path)
Save the chain.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the chain to.
Return type
None
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
to_json()
Return type
Union[langchain.load.serializable.SerializedConstructor, langchain.load.serializable.SerializedNotImplemented]
to_json_not_implemented()
Return type
langchain.load.serializable.SerializedNotImplemented
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the


serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.


Agent Toolkits
Agent toolkits.


langchain.agents.agent_toolkits.create_json_agent(llm, toolkit, callback_manager=None, prefix='You are an agent designed to interact with JSON.\nYour goal is to return a final answer by interacting with the JSON.\nYou have access to the following tools which help you learn more about the JSON you are interacting with.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nDo not make up any information that is not contained in the JSON.\nYour input to the tools should be in the form of `data["key"][0]` where `data` is the JSON blob you are interacting with, and the syntax used is Python. \nYou should only use keys that you know for a fact exist. You must validate that a key exists by seeing it previously when calling `json_spec_list_keys`. \nIf you have not seen a key in one of those responses, you cannot use it.\nYou should only add one key at a time to the path. You cannot add multiple keys at once.\nIf you encounter a "KeyError", go back to the previous key, look at the available keys, and try again.\n\nIf the question does not seem to be related to the JSON, just return "I don\'t know" as the answer.\nAlways begin your interaction with the `json_spec_list_keys` tool with input "data" to see what keys exist in the JSON.\n\nNote that sometimes the value at a given path is large. In this case, you will get an error "Value is a large dictionary, should explore its keys directly".\nIn this case, you should ALWAYS follow up by using the `json_spec_list_keys` tool to see what keys exist at that path.\nDo not simply refer the user to the JSON or a section of the JSON, as this is not a valid answer. Keep digging until you find the


a section of the JSON, as this is not a valid answer. Keep digging until you find the answer and explicitly return it.\n', suffix='Begin!"\n\nQuestion: {input}\nThought: I should look at the keys that exist in data to see what I have access to\n{agent_scratchpad}', format_instructions='Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables=None, verbose=False, agent_executor_kwargs=None, **kwargs)[source]


Construct a json agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.json.toolkit.JsonToolkit) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (str) –
format_instructions (str) –
input_variables (Optional[List[str]]) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor


langchain.agents.agent_toolkits.create_sql_agent(llm, toolkit, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION, callback_manager=None, prefix='You are an agent designed to interact with a SQL database.\nGiven an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.\nUnless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.\nYou can order the results by a relevant column to return the most interesting examples in the database.\nNever query for all the columns from a specific table, only ask for the relevant columns given the question.\nYou have access to tools for interacting with the database.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nYou MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.\n\nDO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.\n\nIf the question does not seem related to the database, just return "I don\'t know" as the answer.\n', suffix=None, format_instructions='Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables=None, top_k=10, max_iterations=15, max_execution_time=None, early_stopping_method='force', verbose=False,


max_iterations=15, max_execution_time=None, early_stopping_method='force', verbose=False, agent_executor_kwargs=None, **kwargs)[source]


Construct a sql agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.sql.toolkit.SQLDatabaseToolkit) –
agent_type (langchain.agents.agent_types.AgentType) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (Optional[str]) –
format_instructions (str) –
input_variables (Optional[List[str]]) –
top_k (int) –
max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –
early_stopping_method (str) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor


langchain.agents.agent_toolkits.create_openapi_agent(llm, toolkit, callback_manager=None, prefix="You are an agent designed to answer questions by making web requests to an API given the openapi spec.\n\nIf the question does not seem related to the API, return I don't know. Do not make up an answer.\nOnly use information provided by the tools to construct your response.\n\nFirst, find the base URL needed to make the request.\n\nSecond, find the relevant paths needed to answer the question. Take note that, sometimes, you might need to make more than one request to more than one path to answer the question.\n\nThird, find the required parameters needed to make the request. For GET requests, these are usually URL parameters and for POST requests, these are request body parameters.\n\nFourth, make the requests needed to answer the question. Ensure that you are sending the correct parameters to the request by checking which parameters are required. For parameters with a fixed set of values, please use the spec to look at which values are allowed.\n\nUse the exact parameter names as listed in the spec, do not make up any names or abbreviate the names of parameters.\nIf you get a not found error, ensure that you are using a path that actually exists in the spec.\n", suffix='Begin!\n\nQuestion: {input}\nThought: I should explore the spec to find the base url for the API.\n{agent_scratchpad}', format_instructions='Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final


Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables=None, max_iterations=15, max_execution_time=None, early_stopping_method='force', verbose=False, return_intermediate_steps=False, agent_executor_kwargs=None, **kwargs)[source]


Construct a json agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.openapi.toolkit.OpenAPIToolkit) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (str) –
format_instructions (str) –
input_variables (Optional[List[str]]) –
max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –
early_stopping_method (str) –
verbose (bool) –
return_intermediate_steps (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor


langchain.agents.agent_toolkits.create_pbi_agent(llm, toolkit, powerbi=None, callback_manager=None, prefix='You are an agent designed to help users interact with a PowerBI Dataset.\n\nAgent has access to a tool that can write a query based on the question and then run those against PowerBI, Microsofts business intelligence tool. The questions from the users should be interpreted as related to the dataset that is available and not general questions about the world. If the question does not seem related to the dataset, just return "This does not appear to be part of this dataset." as the answer.\n\nGiven an input question, ask to run the questions against the dataset, then look at the results and return the answer, the answer should be a complete sentence that answers the question, if multiple rows are asked find a way to write that in a easily readable format for a human, also make sure to represent numbers in readable ways, like 1M instead of 1000000. Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.\n', suffix='Begin!\n\nQuestion: {input}\nThought: I can first ask which tables I have, then how each table is defined and then ask the query tool the question I need, and finally create a nice sentence that answers the question.\n{agent_scratchpad}', format_instructions='Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', examples=None,


know the final answer\nFinal Answer: the final answer to the original input question', examples=None, input_variables=None, top_k=10, verbose=False, agent_executor_kwargs=None, **kwargs)[source]


Construct a pbi agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (Optional[langchain.agents.agent_toolkits.powerbi.toolkit.PowerBIToolkit]) –
powerbi (Optional[langchain.utilities.powerbi.PowerBIDataset]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (str) –
format_instructions (str) –
examples (Optional[str]) –
input_variables (Optional[List[str]]) –
top_k (int) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor


Return type
langchain.agents.agent.AgentExecutor
langchain.agents.agent_toolkits.create_pbi_chat_agent(llm, toolkit, powerbi=None, callback_manager=None, output_parser=None, prefix='Assistant is a large language model built to help users interact with a PowerBI Dataset.\n\nAssistant has access to a tool that can write a query based on the question and then run those against PowerBI, Microsofts business intelligence tool. The questions from the users should be interpreted as related to the dataset that is available and not general questions about the world. If the question does not seem related to the dataset, just return "This does not appear to be part of this dataset." as the answer.\n\nGiven an input question, ask to run the questions against the dataset, then look at the results and return the answer, the answer should be a complete sentence that answers the question, if multiple rows are asked find a way to write that in a easily readable format for a human, also make sure to represent numbers in readable ways, like 1M instead of 1000000. Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.\n', suffix="TOOLS\n------\nAssistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:\n\n{{tools}}\n\n{format_instructions}\n\nUSER'S INPUT\n--------------------\nHere is the user's input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):\n\n{{{{input}}}}\n", examples=None, input_variables=None, memory=None, top_k=10, verbose=False, agent_executor_kwargs=None, **kwargs)[source]
Construct a pbi agent from an Chat LLM and tools.


Construct a pbi agent from an Chat LLM and tools.
If you supply only a toolkit and no powerbi dataset, the same LLM is used for both.
Parameters
llm (langchain.chat_models.base.BaseChatModel) –
toolkit (Optional[langchain.agents.agent_toolkits.powerbi.toolkit.PowerBIToolkit]) –
powerbi (Optional[langchain.utilities.powerbi.PowerBIDataset]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
output_parser (Optional[langchain.agents.agent.AgentOutputParser]) –
prefix (str) –
suffix (str) –
examples (Optional[str]) –
input_variables (Optional[List[str]]) –
memory (Optional[langchain.memory.chat_memory.BaseChatMemory]) –
top_k (int) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
langchain.agents.agent_toolkits.create_python_agent(llm, tool, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION, callback_manager=None, verbose=False, prefix='You are an agent designed to write and execute python code to answer questions.\nYou have access to a python REPL, which you can use to execute python code.\nIf you get an error, debug your code and try again.\nOnly use the output of your code to answer the question. \nYou might know the answer without running any code, but you should still run the code to get the answer.\nIf it does not seem like you can write code to answer the question, just return "I don\'t know" as the answer.\n', agent_executor_kwargs=None, **kwargs)[source]


Construct a python agent from an LLM and tool.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
tool (langchain.tools.python.tool.PythonREPLTool) –
agent_type (langchain.agents.agent_types.AgentType) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
verbose (bool) –
prefix (str) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
langchain.agents.agent_toolkits.create_vectorstore_agent(llm, toolkit, callback_manager=None, prefix='You are an agent designed to answer questions about sets of documents.\nYou have access to tools for interacting with the documents, and the inputs to the tools are questions.\nSometimes, you will be asked to provide sources for your questions, in which case you should use the appropriate tool to do so.\nIf the question does not seem relevant to any of the tools provided, just return "I don\'t know" as the answer.\n', verbose=False, agent_executor_kwargs=None, **kwargs)[source]
Construct a vectorstore agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreToolkit) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
class langchain.agents.agent_toolkits.JsonToolkit(*, spec)[source]


class langchain.agents.agent_toolkits.JsonToolkit(*, spec)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with a JSON spec.
Parameters
spec (langchain.tools.json.tool.JsonSpec) –
Return type
None
attribute spec: langchain.tools.json.tool.JsonSpec [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.SQLDatabaseToolkit(*, db, llm)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with SQL databases.
Parameters
db (langchain.sql_database.SQLDatabase) –
llm (langchain.base_language.BaseLanguageModel) –
Return type
None
attribute db: langchain.sql_database.SQLDatabase [Required]
attribute llm: langchain.base_language.BaseLanguageModel [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
property dialect: str
Return string representation of dialect to use.
class langchain.agents.agent_toolkits.SparkSQLToolkit(*, db, llm)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with Spark SQL.
Parameters
db (langchain.utilities.spark_sql.SparkSQL) –
llm (langchain.base_language.BaseLanguageModel) –
Return type
None
attribute db: langchain.utilities.spark_sql.SparkSQL [Required]
attribute llm: langchain.base_language.BaseLanguageModel [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type


get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.NLAToolkit(*, nla_tools)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Natural Language API Toolkit Definition.
Parameters
nla_tools (Sequence[langchain.agents.agent_toolkits.nla.tool.NLATool]) –
Return type
None
attribute nla_tools: Sequence[langchain.agents.agent_toolkits.nla.tool.NLATool] [Required]
List of API Endpoint Tools.
classmethod from_llm_and_ai_plugin(llm, ai_plugin, requests=None, verbose=False, **kwargs)[source]
Instantiate the toolkit from an OpenAPI Spec URL
Parameters
llm (langchain.base_language.BaseLanguageModel) –
ai_plugin (langchain.tools.plugin.AIPlugin) –
requests (Optional[langchain.requests.Requests]) –
verbose (bool) –
kwargs (Any) –
Return type
langchain.agents.agent_toolkits.nla.toolkit.NLAToolkit
classmethod from_llm_and_ai_plugin_url(llm, ai_plugin_url, requests=None, verbose=False, **kwargs)[source]
Instantiate the toolkit from an OpenAPI Spec URL
Parameters
llm (langchain.base_language.BaseLanguageModel) –
ai_plugin_url (str) –
requests (Optional[langchain.requests.Requests]) –
verbose (bool) –
kwargs (Any) –
Return type
langchain.agents.agent_toolkits.nla.toolkit.NLAToolkit
classmethod from_llm_and_spec(llm, spec, requests=None, verbose=False, **kwargs)[source]
Instantiate the toolkit by creating tools for each operation.
Parameters


Instantiate the toolkit by creating tools for each operation.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
spec (langchain.utilities.openapi.OpenAPISpec) –
requests (Optional[langchain.requests.Requests]) –
verbose (bool) –
kwargs (Any) –
Return type
langchain.agents.agent_toolkits.nla.toolkit.NLAToolkit
classmethod from_llm_and_url(llm, open_api_url, requests=None, verbose=False, **kwargs)[source]
Instantiate the toolkit from an OpenAPI Spec URL
Parameters
llm (langchain.base_language.BaseLanguageModel) –
open_api_url (str) –
requests (Optional[langchain.requests.Requests]) –
verbose (bool) –
kwargs (Any) –
Return type
langchain.agents.agent_toolkits.nla.toolkit.NLAToolkit
get_tools()[source]
Get the tools for all the API operations.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.PowerBIToolkit(*, powerbi, llm, examples=None, max_iterations=5, callback_manager=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with PowerBI dataset.
Parameters
powerbi (langchain.utilities.powerbi.PowerBIDataset) –
llm (langchain.base_language.BaseLanguageModel) –
examples (Optional[str]) –
max_iterations (int) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
Return type
None
attribute callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None
attribute examples: Optional[str] = None


attribute examples: Optional[str] = None
attribute llm: langchain.base_language.BaseLanguageModel [Required]
attribute max_iterations: int = 5
attribute powerbi: langchain.utilities.powerbi.PowerBIDataset [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.OpenAPIToolkit(*, json_agent, requests_wrapper)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with a OpenAPI api.
Parameters
json_agent (langchain.agents.agent.AgentExecutor) –
requests_wrapper (langchain.requests.TextRequestsWrapper) –
Return type
None
attribute json_agent: langchain.agents.agent.AgentExecutor [Required]
attribute requests_wrapper: langchain.requests.TextRequestsWrapper [Required]
classmethod from_llm(llm, json_spec, requests_wrapper, **kwargs)[source]
Create json agent from llm, then initialize.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
json_spec (langchain.tools.json.tool.JsonSpec) –
requests_wrapper (langchain.requests.TextRequestsWrapper) –
kwargs (Any) –
Return type
langchain.agents.agent_toolkits.openapi.toolkit.OpenAPIToolkit
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.VectorStoreToolkit(*, vectorstore_info, llm=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with a vector store.
Parameters


Toolkit for interacting with a vector store.
Parameters
vectorstore_info (langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreInfo) –
llm (langchain.base_language.BaseLanguageModel) –
Return type
None
attribute llm: langchain.base_language.BaseLanguageModel [Optional]
attribute vectorstore_info: langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreInfo [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
langchain.agents.agent_toolkits.create_vectorstore_router_agent(llm, toolkit, callback_manager=None, prefix='You are an agent designed to answer questions.\nYou have access to tools for interacting with different sources, and the inputs to the tools are questions.\nYour main task is to decide which of the tools is relevant for answering question at hand.\nFor complex questions, you can break the question down into sub questions and use tools to answers the sub questions.\n', verbose=False, agent_executor_kwargs=None, **kwargs)[source]
Construct a vectorstore router agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreRouterToolkit) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
class langchain.agents.agent_toolkits.VectorStoreInfo(*, vectorstore, name, description)[source]
Bases: pydantic.main.BaseModel
Information about a vectorstore.
Parameters


Bases: pydantic.main.BaseModel
Information about a vectorstore.
Parameters
vectorstore (langchain.vectorstores.base.VectorStore) –
name (str) –
description (str) –
Return type
None
attribute description: str [Required]
attribute name: str [Required]
attribute vectorstore: langchain.vectorstores.base.VectorStore [Required]
class langchain.agents.agent_toolkits.VectorStoreRouterToolkit(*, vectorstores, llm=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for routing between vector stores.
Parameters
vectorstores (List[langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreInfo]) –
llm (langchain.base_language.BaseLanguageModel) –
Return type
None
attribute llm: langchain.base_language.BaseLanguageModel [Optional]
attribute vectorstores: List[langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreInfo] [Required]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
langchain.agents.agent_toolkits.create_pandas_dataframe_agent(llm, df, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION, callback_manager=None, prefix=None, suffix=None, input_variables=None, verbose=False, return_intermediate_steps=False, max_iterations=15, max_execution_time=None, early_stopping_method='force', agent_executor_kwargs=None, include_df_in_prompt=True, **kwargs)[source]
Construct a pandas agent from an LLM and dataframe.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
df (Any) –
agent_type (langchain.agents.agent_types.AgentType) –


agent_type (langchain.agents.agent_types.AgentType) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (Optional[str]) –
suffix (Optional[str]) –
input_variables (Optional[List[str]]) –
verbose (bool) –
return_intermediate_steps (bool) –
max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –
early_stopping_method (str) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
include_df_in_prompt (Optional[bool]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
langchain.agents.agent_toolkits.create_spark_dataframe_agent(llm, df, callback_manager=None, prefix='\nYou are working with a spark dataframe in Python. The name of the dataframe is `df`.\nYou should use the tools below to answer the question posed of you:', suffix='\nThis is the result of `print(df.first())`:\n{df}\n\nBegin!\nQuestion: {input}\n{agent_scratchpad}', input_variables=None, verbose=False, return_intermediate_steps=False, max_iterations=15, max_execution_time=None, early_stopping_method='force', agent_executor_kwargs=None, **kwargs)[source]
Construct a spark agent from an LLM and dataframe.
Parameters
llm (langchain.llms.base.BaseLLM) –
df (Any) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (str) –
input_variables (Optional[List[str]]) –
verbose (bool) –
return_intermediate_steps (bool) –
max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –


max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –
early_stopping_method (str) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor


langchain.agents.agent_toolkits.create_spark_sql_agent(llm, toolkit, callback_manager=None, prefix='You are an agent designed to interact with Spark SQL.\nGiven an input question, create a syntactically correct Spark SQL query to run, then look at the results of the query and return the answer.\nUnless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.\nYou can order the results by a relevant column to return the most interesting examples in the database.\nNever query for all the columns from a specific table, only ask for the relevant columns given the question.\nYou have access to tools for interacting with the database.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nYou MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.\n\nDO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.\n\nIf the question does not seem related to the database, just return "I don\'t know" as the answer.\n', suffix='Begin!\n\nQuestion: {input}\nThought: I should look at the tables in the database to see what I can query.\n{agent_scratchpad}', format_instructions='Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question', input_variables=None, top_k=10,


Answer: the final answer to the original input question', input_variables=None, top_k=10, max_iterations=15, max_execution_time=None, early_stopping_method='force', verbose=False, agent_executor_kwargs=None, **kwargs)[source]


Construct a sql agent from an LLM and tools.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
toolkit (langchain.agents.agent_toolkits.spark_sql.toolkit.SparkSQLToolkit) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
prefix (str) –
suffix (str) –
format_instructions (str) –
input_variables (Optional[List[str]]) –
top_k (int) –
max_iterations (Optional[int]) –
max_execution_time (Optional[float]) –
early_stopping_method (str) –
verbose (bool) –
agent_executor_kwargs (Optional[Dict[str, Any]]) –
kwargs (Dict[str, Any]) –
Return type
langchain.agents.agent.AgentExecutor
langchain.agents.agent_toolkits.create_csv_agent(llm, path, pandas_kwargs=None, **kwargs)[source]
Create csv agent by loading to a dataframe and using pandas agent.
Parameters
llm (langchain.base_language.BaseLanguageModel) –
path (Union[str, List[str]]) –
pandas_kwargs (Optional[dict]) –
kwargs (Any) –
Return type
langchain.agents.agent.AgentExecutor
class langchain.agents.agent_toolkits.ZapierToolkit(*, tools=[])[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Zapier Toolkit.
Parameters
tools (List[langchain.tools.base.BaseTool]) –
Return type
None
attribute tools: List[langchain.tools.base.BaseTool] = []
classmethod from_zapier_nla_wrapper(zapier_nla_wrapper)[source]
Create a toolkit from a ZapierNLAWrapper.
Parameters


Create a toolkit from a ZapierNLAWrapper.
Parameters
zapier_nla_wrapper (langchain.utilities.zapier.ZapierNLAWrapper) –
Return type
langchain.agents.agent_toolkits.zapier.toolkit.ZapierToolkit
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.GmailToolkit(*, api_resource=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with Gmail.
Parameters
api_resource (Resource) –
Return type
None
attribute api_resource: Resource [Optional]
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.JiraToolkit(*, tools=[])[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Jira Toolkit.
Parameters
tools (List[langchain.tools.base.BaseTool]) –
Return type
None
attribute tools: List[langchain.tools.base.BaseTool] = []
classmethod from_jira_api_wrapper(jira_api_wrapper)[source]
Parameters
jira_api_wrapper (langchain.utilities.jira.JiraAPIWrapper) –
Return type
langchain.agents.agent_toolkits.jira.toolkit.JiraToolkit
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.FileManagementToolkit(*, root_dir=None, selected_tools=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for interacting with a Local Files.
Parameters


Toolkit for interacting with a Local Files.
Parameters
root_dir (Optional[str]) –
selected_tools (Optional[List[str]]) –
Return type
None
attribute root_dir: Optional[str] = None
If specified, all file operations are made relative to root_dir.
attribute selected_tools: Optional[List[str]] = None
If provided, only provide the selected tools. Defaults to all.
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.PlayWrightBrowserToolkit(*, sync_browser=None, async_browser=None)[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for web browser tools.
Parameters
sync_browser (Optional['SyncBrowser']) –
async_browser (Optional['AsyncBrowser']) –
Return type
None
attribute async_browser: Optional['AsyncBrowser'] = None
attribute sync_browser: Optional['SyncBrowser'] = None
classmethod from_browser(sync_browser=None, async_browser=None)[source]
Instantiate the toolkit.
Parameters
sync_browser (Optional[SyncBrowser]) –
async_browser (Optional[AsyncBrowser]) –
Return type
PlayWrightBrowserToolkit
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]
class langchain.agents.agent_toolkits.AzureCognitiveServicesToolkit[source]
Bases: langchain.agents.agent_toolkits.base.BaseToolkit
Toolkit for Azure Cognitive Services.
Return type
None
get_tools()[source]
Get the tools in the toolkit.
Return type
List[langchain.tools.base.BaseTool]