id
stringlengths
14
16
text
stringlengths
31
2.41k
source
stringlengths
53
121
81099a94f427-27
Bases: langchain.chains.llm.LLMChain Chain to have a conversation and load context from memory. Example from langchain import ConversationChain, OpenAI conversation = ConversationChain(llm=OpenAI()) Parameters memory (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]]) – prompt (langchain.prompts.base.BasePromptTemplate) – llm (langchain.base_language.BaseLanguageModel) – output_key (str) – output_parser (langchain.schema.BaseLLMOutputParser) – return_final_only (bool) – llm_kwargs (dict) – input_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 llm: BaseLanguageModel [Required] Language model to call. attribute llm_kwargs: dict [Optional] attribute memory: langchain.schema.BaseMemory [Optional] Default memory store. attribute output_parser: BaseLLMOutputParser [Optional] Output parser to use. Defaults to one that takes the most likely string but does not change it otherwise.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-28
Defaults to one that takes the most likely string but does not change it otherwise. attribute prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['history', 'input'], output_parser=None, partial_variables={}, template='The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:', template_format='f-string', validate_template=True) Default conversation prompt to use. attribute return_final_only: bool = True Whether to return only the final parsed result. Defaults to True. If false, will return a bunch of extra information about the generation. 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 aapply(input_list, callbacks=None) Utilize the LLM generate method for speed gains. 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 aapply_and_parse(input_list, callbacks=None) Call apply and then parse the results. Parameters input_list (List[Dict[str, Any]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-29
Parameters input_list (List[Dict[str, Any]]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type Sequence[Union[str, List[str], Dict[str, str]]] 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 agenerate(input_list, run_manager=None) Generate LLM result from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.AsyncCallbackManagerForChainRun]) – Return type langchain.schema.LLMResult apply(input_list, callbacks=None) Utilize the LLM generate method for speed gains. Parameters input_list (List[Dict[str, Any]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-30
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]] apply_and_parse(input_list, callbacks=None) Call apply and then parse the results. Parameters input_list (List[Dict[str, Any]]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type Sequence[Union[str, List[str], Dict[str, str]]] async apredict(callbacks=None, **kwargs) Format prompt with kwargs and pass to LLM. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to pass to LLMChain **kwargs – Keys to pass to prompt template. kwargs (Any) – Returns Completion from LLM. Return type str Example completion = llm.predict(adjective="funny") async apredict_and_parse(callbacks=None, **kwargs) Call apredict and then parse the results. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – kwargs (Any) – Return type Union[str, List[str], Dict[str, str]] async aprep_prompts(input_list, run_manager=None) Prepare prompts from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.AsyncCallbackManagerForChainRun]) – Return type Tuple[List[langchain.schema.PromptValue], Optional[List[str]]]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-31
Return type Tuple[List[langchain.schema.PromptValue], Optional[List[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 create_outputs(llm_result) Create outputs from response. Parameters llm_result (langchain.schema.LLMResult) – Return type List[Dict[str, Any]] dict(**kwargs) Return dictionary representation of chain. Parameters kwargs (Any) – Return type Dict classmethod from_string(llm, template) Create LLMChain from LLM and template. Parameters llm (langchain.base_language.BaseLanguageModel) – template (str) – Return type langchain.chains.llm.LLMChain generate(input_list, run_manager=None) Generate LLM result from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.CallbackManagerForChainRun]) – Return type langchain.schema.LLMResult predict(callbacks=None, **kwargs) Format prompt with kwargs and pass to LLM. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to pass to LLMChain **kwargs – Keys to pass to prompt template. kwargs (Any) – Returns Completion from LLM. Return type str Example
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-32
Returns Completion from LLM. Return type str Example completion = llm.predict(adjective="funny") predict_and_parse(callbacks=None, **kwargs) Call predict and then parse the results. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – kwargs (Any) – Return type Union[str, List[str], Dict[str, Any]] 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] prep_prompts(input_list, run_manager=None) Prepare prompts from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.CallbackManagerForChainRun]) – Return type Tuple[List[langchain.schema.PromptValue], Optional[List[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:
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-33
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 input_keys: List[str] Use this since so some prompt vars come from history. 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.ConversationalRetrievalChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, combine_docs_chain, question_generator, output_key='answer', return_source_documents=False, return_generated_question=False, get_chat_history=None, retriever, max_tokens_limit=None)[source] Bases: langchain.chains.conversational_retrieval.base.BaseConversationalRetrievalChain Chain for chatting with an index. 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) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-34
verbose (bool) – tags (Optional[List[str]]) – combine_docs_chain (langchain.chains.combine_documents.base.BaseCombineDocumentsChain) – question_generator (langchain.chains.llm.LLMChain) – output_key (str) – return_source_documents (bool) – return_generated_question (bool) – get_chat_history (Optional[Callable[[Union[Tuple[str, str], langchain.schema.BaseMessage]], str]]) – retriever (langchain.schema.BaseRetriever) – max_tokens_limit (Optional[int]) – 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_docs_chain: BaseCombineDocumentsChain [Required] attribute get_chat_history: Optional[Callable[[CHAT_TURN_TYPE], str]] = None Return the source documents. attribute max_tokens_limit: Optional[int] = None If set, restricts the docs to return from store based on tokens, enforced only for StuffDocumentChain 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-35
There are many different types of memory - please see memory docs for the full catalog. attribute output_key: str = 'answer' attribute question_generator: LLMChain [Required] attribute retriever: BaseRetriever [Required] Index to connect to. attribute return_generated_question: bool = False attribute return_source_documents: 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-36
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_llm(llm, retriever, condense_question_prompt=PromptTemplate(input_variables=['chat_history', 'question'], output_parser=None, partial_variables={}, template='Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question, in its original language.\n\nChat History:\n{chat_history}\nFollow Up Input: {question}\nStandalone question:', template_format='f-string', validate_template=True), chain_type='stuff', verbose=False, condense_question_llm=None, combine_docs_chain_kwargs=None, callbacks=None, **kwargs)[source] Load chain from LLM. Parameters llm (langchain.base_language.BaseLanguageModel) – retriever (langchain.schema.BaseRetriever) – condense_question_prompt (langchain.prompts.base.BasePromptTemplate) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-37
condense_question_prompt (langchain.prompts.base.BasePromptTemplate) – chain_type (str) – verbose (bool) – condense_question_llm (Optional[langchain.base_language.BaseLanguageModel]) – combine_docs_chain_kwargs (Optional[Dict]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – kwargs (Any) – Return type langchain.chains.conversational_retrieval.base.BaseConversationalRetrievalChain 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]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-38
to_json_not_implemented() Return type langchain.load.serializable.SerializedNotImplemented property input_keys: List[str] Input keys. 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.FlareChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, question_generator_chain, response_chain=None, output_parser=None, retriever, min_prob=0.2, min_token_gap=5, num_pad_tokens=2, max_iter=10, start_with_retrieval=True)[source] Bases: langchain.chains.base.Chain 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]]) – question_generator_chain (langchain.chains.flare.base.QuestionGeneratorChain) – response_chain (langchain.chains.flare.base._ResponseChain) – output_parser (langchain.chains.flare.prompts.FinishedOutputParser) – retriever (langchain.schema.BaseRetriever) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-39
retriever (langchain.schema.BaseRetriever) – min_prob (float) – min_token_gap (int) – num_pad_tokens (int) – max_iter (int) – start_with_retrieval (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 max_iter: int = 10 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 min_prob: float = 0.2 attribute min_token_gap: int = 5 attribute num_pad_tokens: int = 2 attribute output_parser: FinishedOutputParser [Optional] attribute question_generator_chain: QuestionGeneratorChain [Required] attribute response_chain: _ResponseChain [Optional] attribute retriever: BaseRetriever [Required] attribute start_with_retrieval: bool = True attribute tags: Optional[List[str]] = None Optional list of tags associated with the chain. Defaults to None
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-40
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 input_list (List[Dict[str, Any]]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type List[Dict[str, str]]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-41
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_llm(llm, max_generation_len=32, **kwargs)[source] Parameters llm (langchain.base_language.BaseLanguageModel) – max_generation_len (int) – kwargs (Any) – Return type langchain.chains.flare.base.FlareChain 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-42
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 input_keys: List[str] Input keys this chain expects. 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. property output_keys: List[str] Output keys this chain expects. class langchain.chains.GraphCypherQAChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, graph, cypher_generation_chain, qa_chain, input_key='query', output_key='result', top_k=10, return_intermediate_steps=False, return_direct=False)[source] Bases: langchain.chains.base.Chain Chain for question-answering against a graph by generating Cypher statements. Parameters memory (Optional[langchain.schema.BaseMemory]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-43
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]]) – graph (langchain.graphs.neo4j_graph.Neo4jGraph) – cypher_generation_chain (langchain.chains.llm.LLMChain) – qa_chain (langchain.chains.llm.LLMChain) – input_key (str) – output_key (str) – top_k (int) – return_intermediate_steps (bool) – return_direct (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 cypher_generation_chain: LLMChain [Required] attribute graph: Neo4jGraph [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 qa_chain: LLMChain [Required]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-44
for the full catalog. attribute qa_chain: LLMChain [Required] attribute return_direct: bool = False Whether or not to return the result of querying the graph directly. attribute return_intermediate_steps: bool = False Whether or not to return the intermediate steps along with the final answer. 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 top_k: int = 10 Number of results to return from the query 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-45
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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-46
Parameters kwargs (Any) – Return type Dict classmethod from_llm(llm, *, qa_prompt=PromptTemplate(input_variables=['context', 'question'], output_parser=None, partial_variables={}, template="You are an assistant that helps to form nice and human understandable answers.\nThe information part contains the provided information that you must use to construct an answer.\nThe provided information is authorative, you must never doubt it or try to use your internal knowledge to correct it.\nMake the answer sound as a response to the question. Do not mention that you based the result on the given information.\nIf the provided information is empty, say that you don't know the answer.\nInformation:\n{context}\n\nQuestion: {question}\nHelpful Answer:", template_format='f-string', validate_template=True), cypher_prompt=PromptTemplate(input_variables=['schema', 'question'], output_parser=None, partial_variables={}, template='Task:Generate Cypher statement to query a graph database.\nInstructions:\nUse only the provided relationship types and properties in the schema.\nDo not use any other relationship types or properties that are not provided.\nSchema:\n{schema}\nNote: Do not include any explanations or apologies in your responses.\nDo not respond to any questions that might ask anything else than for you to construct a Cypher statement.\nDo not include any text except the generated Cypher statement.\n\nThe question is:\n{question}', template_format='f-string', validate_template=True), **kwargs)[source] Initialize from LLM. Parameters llm (langchain.base_language.BaseLanguageModel) – qa_prompt (langchain.prompts.base.BasePromptTemplate) – cypher_prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.graph_qa.cypher.GraphCypherQAChain
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-47
Return type langchain.chains.graph_qa.cypher.GraphCypherQAChain 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. eg. [β€œlangchain”, β€œllms”, β€œopenai”]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-48
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.GraphQAChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, graph, entity_extraction_chain, qa_chain, input_key='query', output_key='result')[source] Bases: langchain.chains.base.Chain Chain for question-answering against a graph. 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]]) – graph (langchain.graphs.networkx_graph.NetworkxEntityGraph) – entity_extraction_chain (langchain.chains.llm.LLMChain) – qa_chain (langchain.chains.llm.LLMChain) – 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-49
Each custom chain can optionally call additional callback methods, see Callback docs for full details. attribute entity_extraction_chain: LLMChain [Required] attribute graph: NetworkxEntityGraph [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 qa_chain: LLMChain [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 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-50
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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-51
Parameters kwargs (Any) – Return type Dict classmethod from_llm(llm, qa_prompt=PromptTemplate(input_variables=['context', 'question'], output_parser=None, partial_variables={}, template="Use the following knowledge triplets to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n\n{context}\n\nQuestion: {question}\nHelpful Answer:", template_format='f-string', validate_template=True), entity_prompt=PromptTemplate(input_variables=['input'], output_parser=None, partial_variables={}, template="Extract all entities from the following text. As a guideline, a proper noun is generally capitalized. You should definitely extract all names and places.\n\nReturn the output as a single comma-separated list, or NONE if there is nothing of note to return.\n\nEXAMPLE\ni'm trying to improve Langchain's interfaces, the UX, its integrations with various products the user might want ... a lot of stuff.\nOutput: Langchain\nEND OF EXAMPLE\n\nEXAMPLE\ni'm trying to improve Langchain's interfaces, the UX, its integrations with various products the user might want ... a lot of stuff. I'm working with Sam.\nOutput: Langchain, Sam\nEND OF EXAMPLE\n\nBegin!\n\n{input}\nOutput:", template_format='f-string', validate_template=True), **kwargs)[source] Initialize from LLM. Parameters llm (langchain.base_language.BaseLanguageModel) – qa_prompt (langchain.prompts.base.BasePromptTemplate) – entity_prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.graph_qa.base.GraphQAChain prep_inputs(inputs) Validate and prep inputs. Parameters
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-52
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. eg. [β€œlangchain”, β€œllms”, β€œopenai”] property lc_secrets: Dict[str, str] Return a map of constructor argument names to secret ids.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-53
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.HypotheticalDocumentEmbedder(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, base_embeddings, llm_chain)[source] Bases: langchain.chains.base.Chain, langchain.embeddings.base.Embeddings Generate hypothetical document for query, and then embed that. Based on https://arxiv.org/abs/2212.10496 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]]) – base_embeddings (langchain.embeddings.base.Embeddings) – llm_chain (langchain.chains.llm.LLMChain) – Return type None attribute base_embeddings: Embeddings [Required] 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 llm_chain: LLMChain [Required] attribute memory: Optional[BaseMemory] = None Optional memory object. Defaults to None.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-54
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 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]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-55
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 combine_embeddings(embeddings)[source] Combine embeddings into final embeddings. Parameters embeddings (List[List[float]]) – Return type List[float] dict(**kwargs) Return dictionary representation of chain. Parameters kwargs (Any) – Return type Dict embed_documents(texts)[source] Call the base embeddings. Parameters texts (List[str]) – Return type List[List[float]] embed_query(text)[source] Generate a hypothetical document and embedded it. Parameters text (str) – Return type List[float] classmethod from_llm(llm, base_embeddings, prompt_key, **kwargs)[source] Load and use LLMChain for a specific prompt key. Parameters llm (langchain.base_language.BaseLanguageModel) – base_embeddings (langchain.embeddings.base.Embeddings) – prompt_key (str) – kwargs (Any) – Return type
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-56
prompt_key (str) – kwargs (Any) – Return type langchain.chains.hyde.base.HypotheticalDocumentEmbedder 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 input_keys: List[str] Input keys for Hyde’s LLM chain. 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]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-57
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. property output_keys: List[str] Output keys for Hyde’s LLM chain. class langchain.chains.KuzuQAChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, graph, cypher_generation_chain, qa_chain, input_key='query', output_key='result')[source] Bases: langchain.chains.base.Chain Chain for question-answering against a graph by generating Cypher statements for KΓΉzu. 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]]) – graph (langchain.graphs.kuzu_graph.KuzuGraph) – cypher_generation_chain (langchain.chains.llm.LLMChain) – qa_chain (langchain.chains.llm.LLMChain) – 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-58
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 cypher_generation_chain: LLMChain [Required] attribute graph: KuzuGraph [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 qa_chain: LLMChain [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 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-59
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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-60
classmethod from_llm(llm, *, qa_prompt=PromptTemplate(input_variables=['context', 'question'], output_parser=None, partial_variables={}, template="You are an assistant that helps to form nice and human understandable answers.\nThe information part contains the provided information that you must use to construct an answer.\nThe provided information is authorative, you must never doubt it or try to use your internal knowledge to correct it.\nMake the answer sound as a response to the question. Do not mention that you based the result on the given information.\nIf the provided information is empty, say that you don't know the answer.\nInformation:\n{context}\n\nQuestion: {question}\nHelpful Answer:", template_format='f-string', validate_template=True), cypher_prompt=PromptTemplate(input_variables=['schema', 'question'], output_parser=None, partial_variables={}, template='Task:Generate KΓΉzu Cypher statement to query a graph database.\n\nInstructions:\n\nGenerate statement with KΓΉzu Cypher dialect (rather than standard):\n1. do not use `WHERE EXISTS` clause to check the existence of a property because KΓΉzu database has a fixed schema.\n2. do not omit relationship pattern. Always use `()-[]->()` instead of `()->()`.\n3. do not include any notes or comments even if the statement does not produce the expected result.\n```\n\nUse only the provided relationship types and properties in the schema.\nDo not use any other relationship types or properties that are not provided.\nSchema:\n{schema}\nNote: Do not include any explanations or apologies in your responses.\nDo not respond to any questions that might ask anything else than for you to construct a Cypher statement.\nDo not include any text except the generated Cypher statement.\n\nThe question is:\n{question}', template_format='f-string', validate_template=True), **kwargs)[source]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-61
Initialize from LLM. Parameters llm (langchain.base_language.BaseLanguageModel) – qa_prompt (langchain.prompts.base.BasePromptTemplate) – cypher_prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.graph_qa.kuzu.KuzuQAChain 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-62
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.LLMBashChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, llm_chain, llm=None, input_key='question', output_key='answer', prompt=PromptTemplate(input_variables=['question'], output_parser=BashOutputParser(), partial_variables={}, template='If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put "#!/bin/bash" in your answer. Make sure to reason step by step, using this format:\n\nQuestion: "copy the files in the directory named \'target\' into a new directory at the same level as target called \'myNewDirectory\'"\n\nI need to take the following actions:\n- List all files in the directory\n- Create a new directory\n- Copy the files from the first directory into the second directory\n```bash\nls\nmkdir myNewDirectory\ncp -r target/* myNewDirectory\n```\n\nThat is the format. Begin!\n\nQuestion: {question}', template_format='f-string', validate_template=True), bash_process=None)[source] Bases: langchain.chains.base.Chain Chain that interprets a prompt and executes bash code to perform bash operations.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-63
Chain that interprets a prompt and executes bash code to perform bash operations. Example from langchain import LLMBashChain, OpenAI llm_bash = LLMBashChain.from_llm(OpenAI()) 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]]) – llm_chain (langchain.chains.llm.LLMChain) – llm (Optional[langchain.base_language.BaseLanguageModel]) – input_key (str) – output_key (str) – prompt (langchain.prompts.base.BasePromptTemplate) – bash_process (langchain.utilities.bash.BashProcess) – 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 llm: Optional[BaseLanguageModel] = None [Deprecated] LLM wrapper to use. attribute llm_chain: LLMChain [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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-64
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 prompt: BasePromptTemplate = PromptTemplate(input_variables=['question'], output_parser=BashOutputParser(), partial_variables={}, template='If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put "#!/bin/bash" in your answer. Make sure to reason step by step, using this format:\n\nQuestion: "copy the files in the directory named \'target\' into a new directory at the same level as target called \'myNewDirectory\'"\n\nI need to take the following actions:\n- List all files in the directory\n- Create a new directory\n- Copy the files from the first directory into the second directory\n```bash\nls\nmkdir myNewDirectory\ncp -r target/* myNewDirectory\n```\n\nThat is the format. Begin!\n\nQuestion: {question}', template_format='f-string', validate_template=True) [Deprecated] 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)
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-65
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) Return dictionary representation of chain. Parameters kwargs (Any) – Return type Dict
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-66
Parameters kwargs (Any) – Return type Dict classmethod from_llm(llm, prompt=PromptTemplate(input_variables=['question'], output_parser=BashOutputParser(), partial_variables={}, template='If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put "#!/bin/bash" in your answer. Make sure to reason step by step, using this format:\n\nQuestion: "copy the files in the directory named \'target\' into a new directory at the same level as target called \'myNewDirectory\'"\n\nI need to take the following actions:\n- List all files in the directory\n- Create a new directory\n- Copy the files from the first directory into the second directory\n```bash\nls\nmkdir myNewDirectory\ncp -r target/* myNewDirectory\n```\n\nThat is the format. Begin!\n\nQuestion: {question}', template_format='f-string', validate_template=True), **kwargs)[source] Parameters llm (langchain.base_language.BaseLanguageModel) – prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.llm_bash.base.LLMBashChain 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)
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-67
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 Return whether or not the class is serializable. class langchain.chains.LLMChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, prompt, llm, output_key='text', output_parser=None, return_final_only=True, llm_kwargs=None)[source]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-68
Bases: langchain.chains.base.Chain Chain to run queries against LLMs. Example from langchain import LLMChain, OpenAI, PromptTemplate prompt_template = "Tell me a {adjective} joke" prompt = PromptTemplate( input_variables=["adjective"], template=prompt_template ) llm = LLMChain(llm=OpenAI(), prompt=prompt) 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]]) – prompt (langchain.prompts.base.BasePromptTemplate) – llm (langchain.base_language.BaseLanguageModel) – output_key (str) – output_parser (langchain.schema.BaseLLMOutputParser) – return_final_only (bool) – llm_kwargs (dict) – 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 llm: BaseLanguageModel [Required] Language model to call. attribute llm_kwargs: dict [Optional] attribute memory: Optional[BaseMemory] = None Optional memory object. Defaults to None. Memory is a class that gets called at the start
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-69
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_parser: BaseLLMOutputParser [Optional] Output parser to use. Defaults to one that takes the most likely string but does not change it otherwise. attribute prompt: BasePromptTemplate [Required] Prompt object to use. attribute return_final_only: bool = True Whether to return only the final parsed result. Defaults to True. If false, will return a bunch of extra information about the generation. 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 aapply(input_list, callbacks=None)[source] Utilize the LLM generate method for speed gains. 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 aapply_and_parse(input_list, callbacks=None)[source] Call apply and then parse the results. Parameters input_list (List[Dict[str, Any]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-70
Parameters input_list (List[Dict[str, Any]]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type Sequence[Union[str, List[str], Dict[str, str]]] 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 agenerate(input_list, run_manager=None)[source] Generate LLM result from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.AsyncCallbackManagerForChainRun]) – Return type langchain.schema.LLMResult apply(input_list, callbacks=None)[source] Utilize the LLM generate method for speed gains. Parameters input_list (List[Dict[str, Any]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-71
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]] apply_and_parse(input_list, callbacks=None)[source] Call apply and then parse the results. Parameters input_list (List[Dict[str, Any]]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type Sequence[Union[str, List[str], Dict[str, str]]] async apredict(callbacks=None, **kwargs)[source] Format prompt with kwargs and pass to LLM. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to pass to LLMChain **kwargs – Keys to pass to prompt template. kwargs (Any) – Returns Completion from LLM. Return type str Example completion = llm.predict(adjective="funny") async apredict_and_parse(callbacks=None, **kwargs)[source] Call apredict and then parse the results. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – kwargs (Any) – Return type Union[str, List[str], Dict[str, str]] async aprep_prompts(input_list, run_manager=None)[source] Prepare prompts from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.AsyncCallbackManagerForChainRun]) – Return type Tuple[List[langchain.schema.PromptValue], Optional[List[str]]]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-72
Return type Tuple[List[langchain.schema.PromptValue], Optional[List[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 create_outputs(llm_result)[source] Create outputs from response. Parameters llm_result (langchain.schema.LLMResult) – Return type List[Dict[str, Any]] dict(**kwargs) Return dictionary representation of chain. Parameters kwargs (Any) – Return type Dict classmethod from_string(llm, template)[source] Create LLMChain from LLM and template. Parameters llm (langchain.base_language.BaseLanguageModel) – template (str) – Return type langchain.chains.llm.LLMChain generate(input_list, run_manager=None)[source] Generate LLM result from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.CallbackManagerForChainRun]) – Return type langchain.schema.LLMResult predict(callbacks=None, **kwargs)[source] Format prompt with kwargs and pass to LLM. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Callbacks to pass to LLMChain **kwargs – Keys to pass to prompt template. kwargs (Any) – Returns Completion from LLM. Return type str Example
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-73
Returns Completion from LLM. Return type str Example completion = llm.predict(adjective="funny") predict_and_parse(callbacks=None, **kwargs)[source] Call predict and then parse the results. Parameters callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – kwargs (Any) – Return type Union[str, List[str], Dict[str, Any]] 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] prep_prompts(input_list, run_manager=None)[source] Prepare prompts from inputs. Parameters input_list (List[Dict[str, Any]]) – run_manager (Optional[langchain.callbacks.manager.CallbackManagerForChainRun]) – Return type Tuple[List[langchain.schema.PromptValue], Optional[List[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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-74
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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-75
property lc_serializable: bool Return whether or not the class is serializable. class langchain.chains.LLMCheckerChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, question_to_checked_assertions_chain, llm=None, create_draft_answer_prompt=PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='{question}\n\n', template_format='f-string', validate_template=True), list_assertions_prompt=PromptTemplate(input_variables=['statement'], output_parser=None, partial_variables={}, template='Here is a statement:\n{statement}\nMake a bullet point list of the assumptions you made when producing the above statement.\n\n', template_format='f-string', validate_template=True), check_assertions_prompt=PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='Here is a bullet point list of assertions:\n{assertions}\nFor each assertion, determine whether it is true or false. If it is false, explain why.\n\n', template_format='f-string', validate_template=True), revised_answer_prompt=PromptTemplate(input_variables=['checked_assertions', 'question'], output_parser=None, partial_variables={}, template="{checked_assertions}\n\nQuestion: In light of the above assertions and checks, how would you answer the question '{question}'?\n\nAnswer:", template_format='f-string', validate_template=True), input_key='query', output_key='result')[source] Bases: langchain.chains.base.Chain Chain for question-answering with self-verification. Example from langchain import OpenAI, LLMCheckerChain llm = OpenAI(temperature=0.7) checker_chain = LLMCheckerChain.from_llm(llm) Parameters memory (Optional[langchain.schema.BaseMemory]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-76
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]]) – question_to_checked_assertions_chain (langchain.chains.sequential.SequentialChain) – llm (Optional[langchain.base_language.BaseLanguageModel]) – create_draft_answer_prompt (langchain.prompts.prompt.PromptTemplate) – list_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – check_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – revised_answer_prompt (langchain.prompts.prompt.PromptTemplate) – 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 check_assertions_prompt: PromptTemplate = PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='Here is a bullet point list of assertions:\n{assertions}\nFor each assertion, determine whether it is true or false. If it is false, explain why.\n\n', template_format='f-string', validate_template=True) [Deprecated]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-77
[Deprecated] attribute create_draft_answer_prompt: PromptTemplate = PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='{question}\n\n', template_format='f-string', validate_template=True) [Deprecated] attribute list_assertions_prompt: PromptTemplate = PromptTemplate(input_variables=['statement'], output_parser=None, partial_variables={}, template='Here is a statement:\n{statement}\nMake a bullet point list of the assumptions you made when producing the above statement.\n\n', template_format='f-string', validate_template=True) [Deprecated] attribute llm: Optional[BaseLanguageModel] = None [Deprecated] LLM wrapper to use. 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 question_to_checked_assertions_chain: SequentialChain [Required] attribute revised_answer_prompt: PromptTemplate = PromptTemplate(input_variables=['checked_assertions', 'question'], output_parser=None, partial_variables={}, template="{checked_assertions}\n\nQuestion: In light of the above assertions and checks, how would you answer the question '{question}'?\n\nAnswer:", template_format='f-string', validate_template=True) [Deprecated] Prompt to use when questioning the documents. 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-78
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 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-79
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_llm(llm, create_draft_answer_prompt=PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='{question}\n\n', template_format='f-string', validate_template=True), list_assertions_prompt=PromptTemplate(input_variables=['statement'], output_parser=None, partial_variables={}, template='Here is a statement:\n{statement}\nMake a bullet point list of the assumptions you made when producing the above statement.\n\n', template_format='f-string', validate_template=True), check_assertions_prompt=PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='Here is a bullet point list of assertions:\n{assertions}\nFor each assertion, determine whether it is true or false. If it is false, explain why.\n\n', template_format='f-string', validate_template=True), revised_answer_prompt=PromptTemplate(input_variables=['checked_assertions', 'question'], output_parser=None, partial_variables={}, template="{checked_assertions}\n\nQuestion: In light of the above assertions and checks, how would you answer the question '{question}'?\n\nAnswer:", template_format='f-string', validate_template=True), **kwargs)[source] Parameters llm (langchain.base_language.BaseLanguageModel) – create_draft_answer_prompt (langchain.prompts.prompt.PromptTemplate) – list_assertions_prompt (langchain.prompts.prompt.PromptTemplate) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-80
list_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – check_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – revised_answer_prompt (langchain.prompts.prompt.PromptTemplate) – kwargs (Any) – Return type langchain.chains.llm_checker.base.LLMCheckerChain 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-81
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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-82
property lc_serializable: bool Return whether or not the class is serializable. class langchain.chains.LLMMathChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, llm_chain, llm=None, prompt=PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='Translate a math problem into a expression that can be executed using Python\'s numexpr library. Use the output of running this code to answer the question.\n\nQuestion: ${{Question with math problem.}}\n```text\n${{single line mathematical expression that solves the problem}}\n```\n...numexpr.evaluate(text)...\n```output\n${{Output of running the code}}\n```\nAnswer: ${{Answer}}\n\nBegin.\n\nQuestion: What is 37593 * 67?\n```text\n37593 * 67\n```\n...numexpr.evaluate("37593 * 67")...\n```output\n2518731\n```\nAnswer: 2518731\n\nQuestion: 37593^(1/5)\n```text\n37593**(1/5)\n```\n...numexpr.evaluate("37593**(1/5)")...\n```output\n8.222831614237718\n```\nAnswer: 8.222831614237718\n\nQuestion: {question}\n', template_format='f-string', validate_template=True), input_key='question', output_key='answer')[source] Bases: langchain.chains.base.Chain Chain that interprets a prompt and executes python code to do math. Example from langchain import LLMMathChain, OpenAI llm_math = LLMMathChain.from_llm(OpenAI()) Parameters memory (Optional[langchain.schema.BaseMemory]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-83
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]]) – llm_chain (langchain.chains.llm.LLMChain) – llm (Optional[langchain.base_language.BaseLanguageModel]) – prompt (langchain.prompts.base.BasePromptTemplate) – 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 llm: Optional[BaseLanguageModel] = None [Deprecated] LLM wrapper to use. attribute llm_chain: LLMChain [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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-84
There are many different types of memory - please see memory docs for the full catalog. attribute prompt: BasePromptTemplate = PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='Translate a math problem into a expression that can be executed using Python\'s numexpr library. Use the output of running this code to answer the question.\n\nQuestion: ${{Question with math problem.}}\n```text\n${{single line mathematical expression that solves the problem}}\n```\n...numexpr.evaluate(text)...\n```output\n${{Output of running the code}}\n```\nAnswer: ${{Answer}}\n\nBegin.\n\nQuestion: What is 37593 * 67?\n```text\n37593 * 67\n```\n...numexpr.evaluate("37593 * 67")...\n```output\n2518731\n```\nAnswer: 2518731\n\nQuestion: 37593^(1/5)\n```text\n37593**(1/5)\n```\n...numexpr.evaluate("37593**(1/5)")...\n```output\n8.222831614237718\n```\nAnswer: 8.222831614237718\n\nQuestion: {question}\n', template_format='f-string', validate_template=True) [Deprecated] Prompt to use to translate to python if necessary. 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-85
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]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-86
tags (Optional[List[str]]) – kwargs (Any) – Return type str dict(**kwargs) Return dictionary representation of chain. Parameters kwargs (Any) – Return type Dict classmethod from_llm(llm, prompt=PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='Translate a math problem into a expression that can be executed using Python\'s numexpr library. Use the output of running this code to answer the question.\n\nQuestion: ${{Question with math problem.}}\n```text\n${{single line mathematical expression that solves the problem}}\n```\n...numexpr.evaluate(text)...\n```output\n${{Output of running the code}}\n```\nAnswer: ${{Answer}}\n\nBegin.\n\nQuestion: What is 37593 * 67?\n```text\n37593 * 67\n```\n...numexpr.evaluate("37593 * 67")...\n```output\n2518731\n```\nAnswer: 2518731\n\nQuestion: 37593^(1/5)\n```text\n37593**(1/5)\n```\n...numexpr.evaluate("37593**(1/5)")...\n```output\n8.222831614237718\n```\nAnswer: 8.222831614237718\n\nQuestion: {question}\n', template_format='f-string', validate_template=True), **kwargs)[source] Parameters llm (langchain.base_language.BaseLanguageModel) – prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.llm_math.base.LLMMathChain prep_inputs(inputs) Validate and prep inputs. Parameters
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-87
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. eg. [β€œlangchain”, β€œllms”, β€œopenai”] property lc_secrets: Dict[str, str] Return a map of constructor argument names to secret ids.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-88
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.LLMRequestsChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, llm_chain, requests_wrapper=None, text_length=8000, requests_key='requests_result', input_key='url', output_key='output')[source] Bases: langchain.chains.base.Chain Chain that hits a URL and then uses an LLM to parse 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]]) – llm_chain (langchain.chains.llm.LLMChain) – requests_wrapper (langchain.requests.TextRequestsWrapper) – text_length (int) – requests_key (str) – 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 llm_chain: LLMChain [Required]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-89
for full details. attribute llm_chain: LLMChain [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 requests_wrapper: TextRequestsWrapper [Optional] 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 text_length: int = 8000 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-90
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 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]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-91
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. 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.LLMRouterChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, llm_chain)[source]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-92
Bases: langchain.chains.router.base.RouterChain A router chain that uses an LLM chain to perform routing. 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]]) – llm_chain (langchain.chains.llm.LLMChain) – 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 llm_chain: LLMChain [Required] LLM chain used to perform routing 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 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-93
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 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 aroute(inputs, callbacks=None) Parameters inputs (Dict[str, Any]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-94
Return type langchain.chains.router.base.Route 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_llm(llm, prompt, **kwargs)[source] Convenience constructor. Parameters llm (langchain.base_language.BaseLanguageModel) – prompt (langchain.prompts.base.BasePromptTemplate) – kwargs (Any) – Return type langchain.chains.router.llm_router.LLMRouterChain 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] route(inputs, callbacks=None) Parameters inputs (Dict[str, Any]) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – Return type langchain.chains.router.base.Route run(*args, callbacks=None, tags=None, **kwargs) Run the chain as text in, text out or multiple variables, text out. Parameters
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-95
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 Return whether or not the class is serializable. property output_keys: List[str] Output keys this chain expects.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-96
class langchain.chains.LLMSummarizationCheckerChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, sequential_chain, llm=None, create_assertions_prompt=PromptTemplate(input_variables=['summary'], output_parser=None, partial_variables={}, template='Given some text, extract a list of facts from the text.\n\nFormat your output as a bulleted list.\n\nText:\n"""\n{summary}\n"""\n\nFacts:', template_format='f-string', validate_template=True), check_assertions_prompt=PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='You are an expert fact checker. You have been hired by a major news organization to fact check a very important story.\n\nHere is a bullet point list of facts:\n"""\n{assertions}\n"""\n\nFor each fact, determine whether it is true or false about the subject. If you are unable to determine whether the fact is true or false, output "Undetermined".\nIf the fact is false, explain why.\n\n', template_format='f-string', validate_template=True), revised_summary_prompt=PromptTemplate(input_variables=['checked_assertions', 'summary'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false. If the answer is false, a suggestion is given for a correction.\n\nChecked Assertions:\n"""\n{checked_assertions}\n"""\n\nOriginal Summary:\n"""\n{summary}\n"""\n\nUsing these checked assertions, rewrite the original summary to be completely true.\n\nThe output should have the same structure and formatting as the original summary.\n\nSummary:', template_format='f-string', validate_template=True), are_all_true_prompt=PromptTemplate(input_variables=['checked_assertions'], output_parser=None, partial_variables={}, template='Below are
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-97
output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false.\n\nIf all of the assertions are true, return "True". If any of the assertions are false, return "False".\n\nHere are some examples:\n===\n\nChecked Assertions: """\n- The sky is red: False\n- Water is made of lava: False\n- The sun is a star: True\n"""\nResult: False\n\n===\n\nChecked Assertions: """\n- The sky is blue: True\n- Water is wet: True\n- The sun is a star: True\n"""\nResult: True\n\n===\n\nChecked Assertions: """\n- The sky is blue - True\n- Water is made of lava- False\n- The sun is a star - True\n"""\nResult: False\n\n===\n\nChecked Assertions:"""\n{checked_assertions}\n"""\nResult:', template_format='f-string', validate_template=True), input_key='query', output_key='result', max_checks=2)[source]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-98
Bases: langchain.chains.base.Chain Chain for question-answering with self-verification. Example from langchain import OpenAI, LLMSummarizationCheckerChain llm = OpenAI(temperature=0.0) checker_chain = LLMSummarizationCheckerChain.from_llm(llm) 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]]) – sequential_chain (langchain.chains.sequential.SequentialChain) – llm (Optional[langchain.base_language.BaseLanguageModel]) – create_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – check_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – revised_summary_prompt (langchain.prompts.prompt.PromptTemplate) – are_all_true_prompt (langchain.prompts.prompt.PromptTemplate) – input_key (str) – output_key (str) – max_checks (int) – Return type None
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-99
max_checks (int) – Return type None attribute are_all_true_prompt: PromptTemplate = PromptTemplate(input_variables=['checked_assertions'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false.\n\nIf all of the assertions are true, return "True". If any of the assertions are false, return "False".\n\nHere are some examples:\n===\n\nChecked Assertions: """\n- The sky is red: False\n- Water is made of lava: False\n- The sun is a star: True\n"""\nResult: False\n\n===\n\nChecked Assertions: """\n- The sky is blue: True\n- Water is wet: True\n- The sun is a star: True\n"""\nResult: True\n\n===\n\nChecked Assertions: """\n- The sky is blue - True\n- Water is made of lava- False\n- The sun is a star - True\n"""\nResult: False\n\n===\n\nChecked Assertions:"""\n{checked_assertions}\n"""\nResult:', template_format='f-string', validate_template=True) [Deprecated] 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-100
Each custom chain can optionally call additional callback methods, see Callback docs for full details. attribute check_assertions_prompt: PromptTemplate = PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='You are an expert fact checker. You have been hired by a major news organization to fact check a very important story.\n\nHere is a bullet point list of facts:\n"""\n{assertions}\n"""\n\nFor each fact, determine whether it is true or false about the subject. If you are unable to determine whether the fact is true or false, output "Undetermined".\nIf the fact is false, explain why.\n\n', template_format='f-string', validate_template=True) [Deprecated] attribute create_assertions_prompt: PromptTemplate = PromptTemplate(input_variables=['summary'], output_parser=None, partial_variables={}, template='Given some text, extract a list of facts from the text.\n\nFormat your output as a bulleted list.\n\nText:\n"""\n{summary}\n"""\n\nFacts:', template_format='f-string', validate_template=True) [Deprecated] attribute llm: Optional[BaseLanguageModel] = None [Deprecated] LLM wrapper to use. attribute max_checks: int = 2 Maximum number of times to check the assertions. Default to double-checking. 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-101
There are many different types of memory - please see memory docs for the full catalog. attribute revised_summary_prompt: PromptTemplate = PromptTemplate(input_variables=['checked_assertions', 'summary'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false. If the answer is false, a suggestion is given for a correction.\n\nChecked Assertions:\n"""\n{checked_assertions}\n"""\n\nOriginal Summary:\n"""\n{summary}\n"""\n\nUsing these checked assertions, rewrite the original summary to be completely true.\n\nThe output should have the same structure and formatting as the original summary.\n\nSummary:', template_format='f-string', validate_template=True) [Deprecated] attribute sequential_chain: SequentialChain [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 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-102
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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-103
classmethod from_llm(llm, create_assertions_prompt=PromptTemplate(input_variables=['summary'], output_parser=None, partial_variables={}, template='Given some text, extract a list of facts from the text.\n\nFormat your output as a bulleted list.\n\nText:\n"""\n{summary}\n"""\n\nFacts:', template_format='f-string', validate_template=True), check_assertions_prompt=PromptTemplate(input_variables=['assertions'], output_parser=None, partial_variables={}, template='You are an expert fact checker. You have been hired by a major news organization to fact check a very important story.\n\nHere is a bullet point list of facts:\n"""\n{assertions}\n"""\n\nFor each fact, determine whether it is true or false about the subject. If you are unable to determine whether the fact is true or false, output "Undetermined".\nIf the fact is false, explain why.\n\n', template_format='f-string', validate_template=True), revised_summary_prompt=PromptTemplate(input_variables=['checked_assertions', 'summary'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false. If the answer is false, a suggestion is given for a correction.\n\nChecked Assertions:\n"""\n{checked_assertions}\n"""\n\nOriginal Summary:\n"""\n{summary}\n"""\n\nUsing these checked assertions, rewrite the original summary to be completely true.\n\nThe output should have the same structure and formatting as the original summary.\n\nSummary:', template_format='f-string', validate_template=True), are_all_true_prompt=PromptTemplate(input_variables=['checked_assertions'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled as true or false.\n\nIf all of the assertions are true, return "True". If any
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-104
true or false.\n\nIf all of the assertions are true, return "True". If any of the assertions are false, return "False".\n\nHere are some examples:\n===\n\nChecked Assertions: """\n- The sky is red: False\n- Water is made of lava: False\n- The sun is a star: True\n"""\nResult: False\n\n===\n\nChecked Assertions: """\n- The sky is blue: True\n- Water is wet: True\n- The sun is a star: True\n"""\nResult: True\n\n===\n\nChecked Assertions: """\n- The sky is blue - True\n- Water is made of lava- False\n- The sun is a star - True\n"""\nResult: False\n\n===\n\nChecked Assertions:"""\n{checked_assertions}\n"""\nResult:', template_format='f-string', validate_template=True), verbose=False, **kwargs)[source]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-105
Parameters llm (langchain.base_language.BaseLanguageModel) – create_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – check_assertions_prompt (langchain.prompts.prompt.PromptTemplate) – revised_summary_prompt (langchain.prompts.prompt.PromptTemplate) – are_all_true_prompt (langchain.prompts.prompt.PromptTemplate) – verbose (bool) – kwargs (Any) – Return type langchain.chains.llm_summarization_checker.base.LLMSummarizationCheckerChain 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]
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-106
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.MapReduceChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, combine_documents_chain, text_splitter, input_key='input_text', output_key='output_text')[source] Bases: langchain.chains.base.Chain Map-reduce chain. 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) – text_splitter (langchain.text_splitter.TextSplitter) – 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-107
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 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 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 text_splitter: TextSplitter [Required] Text splitter to use. 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-108
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_params(llm, prompt, text_splitter, callbacks=None, combine_chain_kwargs=None, reduce_chain_kwargs=None, **kwargs)[source] Construct a map-reduce chain that uses the chain for map and reduce. Parameters
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-109
Construct a map-reduce chain that uses the chain for map and reduce. Parameters llm (langchain.base_language.BaseLanguageModel) – prompt (langchain.prompts.base.BasePromptTemplate) – text_splitter (langchain.text_splitter.TextSplitter) – callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – combine_chain_kwargs (Optional[Mapping[str, Any]]) – reduce_chain_kwargs (Optional[Mapping[str, Any]]) – kwargs (Any) – Return type langchain.chains.mapreduce.MapReduceChain 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-110
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.MultiPromptChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, router_chain, destination_chains, default_chain, silent_errors=False)[source] Bases: langchain.chains.router.base.MultiRouteChain A multi-route chain that uses an LLM router chain to choose amongst prompts. 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]]) – router_chain (langchain.chains.router.base.RouterChain) – destination_chains (Mapping[str, langchain.chains.llm.LLMChain]) – default_chain (langchain.chains.llm.LLMChain) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-111
default_chain (langchain.chains.llm.LLMChain) – silent_errors (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 default_chain: LLMChain [Required] Default chain to use when router doesn’t map input to one of the destinations. attribute destination_chains: Mapping[str, LLMChain] [Required] Map of name to candidate chains that inputs can be routed to. 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 router_chain: RouterChain [Required] Chain for deciding a destination chain and the input to it. attribute silent_errors: bool = False If True, use default_chain when an invalid destination name is provided. Defaults to 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-112
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 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) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-113
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_prompts(llm, prompt_infos, default_chain=None, **kwargs)[source] Convenience constructor for instantiating from destination prompts. Parameters llm (langchain.base_language.BaseLanguageModel) – prompt_infos (List[Dict[str, str]]) – default_chain (Optional[langchain.chains.llm.LLMChain]) – kwargs (Any) – Return type langchain.chains.router.multi_prompt.MultiPromptChain 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-114
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.MultiRetrievalQAChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, router_chain, destination_chains, default_chain, silent_errors=False)[source] Bases: langchain.chains.router.base.MultiRouteChain A multi-route chain that uses an LLM router chain to choose amongst retrieval qa chains. 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) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-115
verbose (bool) – tags (Optional[List[str]]) – router_chain (langchain.chains.router.llm_router.LLMRouterChain) – destination_chains (Mapping[str, langchain.chains.retrieval_qa.base.BaseRetrievalQA]) – default_chain (langchain.chains.base.Chain) – silent_errors (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 default_chain: Chain [Required] Default chain to use when router doesn’t map input to one of the destinations. attribute destination_chains: Mapping[str, BaseRetrievalQA] [Required] Map of name to candidate chains that inputs can be routed to. 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 router_chain: LLMRouterChain [Required] Chain for deciding a destination chain and the input to it. attribute silent_errors: bool = False If True, use default_chain when an invalid destination name is provided. Defaults to False.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-116
If True, use default_chain when an invalid destination name is provided. Defaults to 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 input_list (List[Dict[str, Any]]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-117
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_retrievers(llm, retriever_infos, default_retriever=None, default_prompt=None, default_chain=None, **kwargs)[source] Parameters llm (langchain.base_language.BaseLanguageModel) – retriever_infos (List[Dict[str, Any]]) – default_retriever (Optional[langchain.schema.BaseRetriever]) – default_prompt (Optional[langchain.prompts.prompt.PromptTemplate]) – default_chain (Optional[langchain.chains.base.Chain]) – kwargs (Any) – Return type langchain.chains.router.multi_retrieval_qa.MultiRetrievalQAChain 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]) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-118
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. 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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-119
property lc_serializable: bool Return whether or not the class is serializable. class langchain.chains.MultiRouteChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, router_chain, destination_chains, default_chain, silent_errors=False)[source] Bases: langchain.chains.base.Chain Use a single chain to route an input to one of multiple candidate chains. 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]]) – router_chain (langchain.chains.router.base.RouterChain) – destination_chains (Mapping[str, langchain.chains.base.Chain]) – default_chain (langchain.chains.base.Chain) – silent_errors (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 default_chain: Chain [Required] Default chain to use when none of the destination chains are suitable. attribute destination_chains: Mapping[str, Chain] [Required] Chains that return final answer to inputs. attribute memory: Optional[BaseMemory] = None Optional memory object. Defaults to None.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-120
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 router_chain: RouterChain [Required] Chain that routes inputs to destination chains. attribute silent_errors: bool = False If True, use default_chain when an invalid destination name is provided. Defaults to 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
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-121
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 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) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-122
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 Return whether or not the class is serializable. class langchain.chains.NatBotChain(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, llm_chain, objective, llm=None, input_url_key='url', input_browser_content_key='browser_content', previous_command='', output_key='command')[source] Bases: langchain.chains.base.Chain Implement an LLM driven browser. Example from langchain import NatBotChain
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-123
Implement an LLM driven browser. Example from langchain import NatBotChain natbot = NatBotChain.from_default("Buy me a new hat.") 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]]) – llm_chain (langchain.chains.llm.LLMChain) – objective (str) – llm (Optional[langchain.base_language.BaseLanguageModel]) – input_url_key (str) – input_browser_content_key (str) – previous_command (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 llm: Optional[BaseLanguageModel] = None [Deprecated] LLM wrapper to use. attribute llm_chain: LLMChain [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.
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-124
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 objective: str [Required] Objective that NatBot is tasked with completing. 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)
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-125
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 execute(url, browser_content)[source] Figure out next browser command to run. Parameters url (str) – URL of the site currently on. browser_content (str) – Content of the page as currently displayed by the browser. Returns Next browser command to run. Return type str Example browser_content = "...." llm_command = natbot.run("www.google.com", browser_content) classmethod from_default(objective, **kwargs)[source] Load with default LLMChain. Parameters objective (str) – kwargs (Any) – Return type langchain.chains.natbot.base.NatBotChain classmethod from_llm(llm, objective, **kwargs)[source] Load from LLM. Parameters llm (langchain.base_language.BaseLanguageModel) – objective (str) – kwargs (Any) –
https://api.python.langchain.com/en/latest/modules/chains.html
81099a94f427-126
objective (str) – kwargs (Any) – Return type langchain.chains.natbot.base.NatBotChain 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.
https://api.python.langchain.com/en/latest/modules/chains.html