langchain_experimental API Reference

langchain_experimental.agents

Functions

agents.agent_toolkits.csv.base.create_csv_agent(...)

Create csv agent by loading to a dataframe and using pandas agent.

agents.agent_toolkits.pandas.base.create_pandas_dataframe_agent(llm, df)

Construct a pandas agent from an LLM and dataframe.

agents.agent_toolkits.python.base.create_python_agent(...)

Construct a python agent from an LLM and tool.

agents.agent_toolkits.spark.base.create_spark_dataframe_agent(llm, df)

Construct a Spark agent from an LLM and dataframe.

agents.agent_toolkits.xorbits.base.create_xorbits_agent(...)

Construct a xorbits agent from an LLM and dataframe.

langchain_experimental.autonomous_agents

Classes

autonomous_agents.autogpt.agent.AutoGPT(...)

Agent class for interacting with Auto-GPT.

autonomous_agents.autogpt.memory.AutoGPTMemory

Memory for AutoGPT.

autonomous_agents.autogpt.output_parser.AutoGPTAction(...)

Action returned by AutoGPTOutputParser.

autonomous_agents.autogpt.output_parser.AutoGPTOutputParser

Output parser for AutoGPT.

autonomous_agents.autogpt.output_parser.BaseAutoGPTOutputParser

Base Output parser for AutoGPT.

autonomous_agents.autogpt.prompt.AutoGPTPrompt

Prompt for AutoGPT.

autonomous_agents.autogpt.prompt_generator.PromptGenerator()

A class for generating custom prompt strings.

autonomous_agents.baby_agi.baby_agi.BabyAGI

Controller model for the BabyAGI agent.

autonomous_agents.baby_agi.task_creation.TaskCreationChain

Chain generating tasks.

autonomous_agents.baby_agi.task_execution.TaskExecutionChain

Chain to execute tasks.

autonomous_agents.baby_agi.task_prioritization.TaskPrioritizationChain

Chain to prioritize tasks.

autonomous_agents.hugginggpt.hugginggpt.HuggingGPT(...)

autonomous_agents.hugginggpt.repsonse_generator.ResponseGenerationChain

Chain to execute tasks.

autonomous_agents.hugginggpt.repsonse_generator.ResponseGenerator(...)

autonomous_agents.hugginggpt.task_executor.Task(...)

autonomous_agents.hugginggpt.task_executor.TaskExecutor(plan)

Load tools to execute tasks.

autonomous_agents.hugginggpt.task_planner.BasePlanner

Create a new model by parsing and validating input data from keyword arguments.

autonomous_agents.hugginggpt.task_planner.Plan(steps)

autonomous_agents.hugginggpt.task_planner.PlanningOutputParser

Create a new model by parsing and validating input data from keyword arguments.

autonomous_agents.hugginggpt.task_planner.Step(...)

autonomous_agents.hugginggpt.task_planner.TaskPlaningChain

Chain to execute tasks.

autonomous_agents.hugginggpt.task_planner.TaskPlanner

Create a new model by parsing and validating input data from keyword arguments.

Functions

autonomous_agents.autogpt.output_parser.preprocess_json_input(...)

Preprocesses a string to be parsed as json.

autonomous_agents.autogpt.prompt_generator.get_prompt(tools)

Generates a prompt string.

autonomous_agents.hugginggpt.repsonse_generator.load_response_generator(llm)

autonomous_agents.hugginggpt.task_planner.load_chat_planner(llm)

langchain_experimental.chat_models

Chat Models are a variation on language models.

While Chat Models use language models under the hood, the interface they expose is a bit different. Rather than expose a “text in, text out” API, they expose an interface where “chat messages” are the inputs and outputs.

Class hierarchy:

BaseLanguageModel --> BaseChatModel --> <name>  # Examples: ChatOpenAI, ChatGooglePalm

Main helpers:

AIMessage, BaseMessage, HumanMessage

Classes

chat_models.llm_wrapper.ChatWrapper

Create a new model by parsing and validating input data from keyword arguments.

chat_models.llm_wrapper.Llama2Chat

Create a new model by parsing and validating input data from keyword arguments.

chat_models.llm_wrapper.Orca

Create a new model by parsing and validating input data from keyword arguments.

chat_models.llm_wrapper.Vicuna

Create a new model by parsing and validating input data from keyword arguments.

langchain_experimental.comprehend_moderation

Classes

comprehend_moderation.amazon_comprehend_moderation.AmazonComprehendModerationChain

A subclass of Chain, designed to apply moderation to LLMs.

comprehend_moderation.base_moderation.BaseModeration(client)

comprehend_moderation.base_moderation_callbacks.BaseModerationCallbackHandler()

comprehend_moderation.base_moderation_config.BaseModerationConfig

Create a new model by parsing and validating input data from keyword arguments.

comprehend_moderation.base_moderation_config.ModerationPiiConfig

Create a new model by parsing and validating input data from keyword arguments.

comprehend_moderation.base_moderation_config.ModerationPromptSafetyConfig

Create a new model by parsing and validating input data from keyword arguments.

comprehend_moderation.base_moderation_config.ModerationToxicityConfig

Create a new model by parsing and validating input data from keyword arguments.

comprehend_moderation.base_moderation_exceptions.ModerationPiiError([...])

Exception raised if PII entities are detected.

comprehend_moderation.base_moderation_exceptions.ModerationPromptSafetyError([...])

Exception raised if Intention entities are detected.

comprehend_moderation.base_moderation_exceptions.ModerationToxicityError([...])

Exception raised if Toxic entities are detected.

comprehend_moderation.pii.ComprehendPII(client)

comprehend_moderation.prompt_safety.ComprehendPromptSafety(client)

comprehend_moderation.toxicity.ComprehendToxicity(client)

langchain_experimental.cpal

Classes

cpal.base.CPALChain

Causal program-aided language (CPAL) chain implementation.

cpal.base.CausalChain

Translate the causal narrative into a stack of operations.

cpal.base.InterventionChain

Set the hypothetical conditions for the causal model.

cpal.base.NarrativeChain

Decompose the narrative into its story elements

cpal.base.QueryChain

Query the outcome table using SQL.

cpal.constants.Constant(value[, names, ...])

Enum for constants used in the CPAL.

cpal.models.CausalModel

Create a new model by parsing and validating input data from keyword arguments.

cpal.models.EntityModel

Create a new model by parsing and validating input data from keyword arguments.

cpal.models.EntitySettingModel

Initial conditions for an entity

cpal.models.InterventionModel

aka initial conditions

cpal.models.NarrativeModel

Represent the narrative input as three story elements.

cpal.models.QueryModel

translate a question about the story outcome into a programmatic expression

cpal.models.ResultModel

Create a new model by parsing and validating input data from keyword arguments.

cpal.models.StoryModel

Create a new model by parsing and validating input data from keyword arguments.

cpal.models.SystemSettingModel

Initial global conditions for the system.

langchain_experimental.data_anonymizer

Data anonymizer package

Classes

data_anonymizer.base.AnonymizerBase()

Base abstract class for anonymizers. It is public and non-virtual because it allows wrapping the behavior for all methods in a base class.

data_anonymizer.base.ReversibleAnonymizerBase()

Base abstract class for reversible anonymizers.

data_anonymizer.deanonymizer_mapping.DeanonymizerMapping(...)

data_anonymizer.presidio.PresidioAnonymizer([...])

param analyzed_fields

List of fields to detect and then anonymize.

data_anonymizer.presidio.PresidioAnonymizerBase([...])

param analyzed_fields

List of fields to detect and then anonymize.

data_anonymizer.presidio.PresidioReversibleAnonymizer([...])

param analyzed_fields

List of fields to detect and then anonymize.

Functions

data_anonymizer.deanonymizer_mapping.create_anonymizer_mapping(...)

Creates or updates the mapping used to anonymize and/or deanonymize text.

data_anonymizer.deanonymizer_mapping.format_duplicated_operator(...)

Format the operator name with the count

data_anonymizer.deanonymizer_matching_strategies.case_insensitive_matching_strategy(...)

Case insensitive matching strategy for deanonymization. It replaces all the anonymized entities with the original ones irrespective of their letter case.

data_anonymizer.deanonymizer_matching_strategies.combined_exact_fuzzy_matching_strategy(...)

RECOMMENDED STRATEGY.

data_anonymizer.deanonymizer_matching_strategies.exact_matching_strategy(...)

Exact matching strategy for deanonymization.

data_anonymizer.deanonymizer_matching_strategies.fuzzy_matching_strategy(...)

Fuzzy matching strategy for deanonymization.

data_anonymizer.deanonymizer_matching_strategies.ngram_fuzzy_matching_strategy(...)

N-gram fuzzy matching strategy for deanonymization.

data_anonymizer.faker_presidio_mapping.get_pseudoanonymizer_mapping([seed])

langchain_experimental.fallacy_removal

The Chain runs a self-review of logical fallacies as determined by this paper categorizing and defining logical fallacies https://arxiv.org/pdf/2212.07425.pdf. Modeled after Constitutional AI and in same format, but applying logical fallacies as generalized rules to remove in output

Classes

fallacy_removal.base.FallacyChain

Chain for applying logical fallacy evaluations, modeled after Constitutional AI and in same format, but applying logical fallacies as generalized rules to remove in output

fallacy_removal.models.LogicalFallacy

Class for a logical fallacy.

langchain_experimental.generative_agents

Generative Agents primitives.

Classes

generative_agents.generative_agent.GenerativeAgent

An Agent as a character with memory and innate characteristics.

generative_agents.memory.GenerativeAgentMemory

Memory for the generative agent.

langchain_experimental.graph_transformers

Classes

graph_transformers.diffbot.DiffbotGraphTransformer([...])

Transforms documents into graph documents using Diffbot's NLP API.

graph_transformers.diffbot.NodesList()

Manages a list of nodes with associated properties.

graph_transformers.diffbot.SimplifiedSchema()

Provides functionality for working with a simplified schema mapping.

Functions

graph_transformers.diffbot.format_property_key(s)

langchain_experimental.llm_bash

Chain that interprets a prompt and executes bash code to perform bash operations.

Classes

llm_bash.base.LLMBashChain

Chain that interprets a prompt and executes bash operations.

llm_bash.bash.BashProcess([strip_newlines, ...])

Wrapper class for starting subprocesses.

llm_bash.prompt.BashOutputParser

Parser for bash output.

langchain_experimental.llm_symbolic_math

Chain that interprets a prompt and executes python code to do math.

Heavily borrowed from llm_math, wrapper for SymPy

Classes

llm_symbolic_math.base.LLMSymbolicMathChain

Chain that interprets a prompt and executes python code to do symbolic math.

langchain_experimental.llms

Experimental LLM wrappers.

Classes

llms.anthropic_functions.AnthropicFunctions

Create a new model by parsing and validating input data from keyword arguments.

llms.anthropic_functions.TagParser()

A heavy-handed solution, but it's fast for prototyping.

llms.jsonformer_decoder.JsonFormer

Jsonformer wrapped LLM using HuggingFace Pipeline API.

llms.llamaapi.ChatLlamaAPI

Create a new model by parsing and validating input data from keyword arguments.

llms.lmformatenforcer_decoder.LMFormatEnforcer

LMFormatEnforcer wrapped LLM using HuggingFace Pipeline API.

llms.ollama_functions.OllamaFunctions

Create a new model by parsing and validating input data from keyword arguments.

llms.rellm_decoder.RELLM

RELLM wrapped LLM using HuggingFace Pipeline API.

Functions

llms.jsonformer_decoder.import_jsonformer()

Lazily import jsonformer.

llms.lmformatenforcer_decoder.import_lmformatenforcer()

Lazily import lmformatenforcer.

llms.rellm_decoder.import_rellm()

Lazily import rellm.

langchain_experimental.open_clip

Classes

open_clip.open_clip.OpenCLIPEmbeddings

Create a new model by parsing and validating input data from keyword arguments.

langchain_experimental.pal_chain

Implements Program-Aided Language Models.

As in https://arxiv.org/pdf/2211.10435.pdf.

This is vulnerable to arbitrary code execution: https://github.com/langchain-ai/langchain/issues/5872

Classes

pal_chain.base.PALChain

Implements Program-Aided Language Models (PAL).

pal_chain.base.PALValidation([...])

Initialize a PALValidation instance.

langchain_experimental.plan_and_execute

Classes

plan_and_execute.agent_executor.PlanAndExecute

Plan and execute a chain of steps.

plan_and_execute.executors.base.BaseExecutor

Base executor.

plan_and_execute.executors.base.ChainExecutor

Chain executor.

plan_and_execute.planners.base.BasePlanner

Base planner.

plan_and_execute.planners.base.LLMPlanner

LLM planner.

plan_and_execute.planners.chat_planner.PlanningOutputParser

Planning output parser.

plan_and_execute.schema.BaseStepContainer

Base step container.

plan_and_execute.schema.ListStepContainer

List step container.

plan_and_execute.schema.Plan

Plan.

plan_and_execute.schema.PlanOutputParser

Plan output parser.

plan_and_execute.schema.Step

Step.

plan_and_execute.schema.StepResponse

Step response.

Functions

plan_and_execute.executors.agent_executor.load_agent_executor(...)

Load an agent executor.

plan_and_execute.planners.chat_planner.load_chat_planner(llm)

Load a chat planner.

langchain_experimental.prompt_injection_identifier

HuggingFace Security toolkit.

Classes

prompt_injection_identifier.hugging_face_identifier.HuggingFaceInjectionIdentifier

Tool that uses HF model to detect prompt injection attacks.

Functions

langchain_experimental.prompts

Functions

prompts.load.load_prompt(path)

Unified method for loading a prompt from LangChainHub or local fs.

langchain_experimental.retrievers

Classes

retrievers.vector_sql_database.VectorSQLDatabaseChainRetriever

Retriever that uses SQLDatabase as Retriever

langchain_experimental.rl_chain

Classes

rl_chain.base.AutoSelectionScorer

Create a new model by parsing and validating input data from keyword arguments.

rl_chain.base.Embedder(*args, **kwargs)

rl_chain.base.Event(inputs[, selected])

rl_chain.base.Policy(**kwargs)

rl_chain.base.RLChain

The RLChain class leverages the Vowpal Wabbit (VW) model as a learned policy for reinforcement learning.

rl_chain.base.Selected()

rl_chain.base.SelectionScorer

Abstract method to grade the chosen selection or the response of the llm

rl_chain.base.VwPolicy(model_repo, vw_cmd, ...)

rl_chain.metrics.MetricsTrackerAverage(step)

rl_chain.metrics.MetricsTrackerRollingWindow(...)

rl_chain.model_repository.ModelRepository(folder)

rl_chain.pick_best_chain.PickBest

PickBest is a class designed to leverage the Vowpal Wabbit (VW) model for reinforcement learning with a context, with the goal of modifying the prompt before the LLM call.

rl_chain.pick_best_chain.PickBestEvent(...)

rl_chain.pick_best_chain.PickBestFeatureEmbedder(...)

Text Embedder class that embeds the BasedOn and ToSelectFrom inputs into a format that can be used by the learning policy

rl_chain.pick_best_chain.PickBestRandomPolicy(...)

rl_chain.pick_best_chain.PickBestSelected([...])

rl_chain.vw_logger.VwLogger(path)

Functions

rl_chain.base.BasedOn(anything)

rl_chain.base.Embed(anything[, keep])

rl_chain.base.EmbedAndKeep(anything)

rl_chain.base.ToSelectFrom(anything)

rl_chain.base.embed(to_embed, model[, namespace])

Embeds the actions or context using the SentenceTransformer model (or a model that has an encode function)

rl_chain.base.embed_dict_type(item, model)

Helper function to embed a dictionary item.

rl_chain.base.embed_list_type(item, model[, ...])

rl_chain.base.embed_string_type(item, model)

Helper function to embed a string or an _Embed object.

rl_chain.base.get_based_on_and_to_select_from(inputs)

rl_chain.base.is_stringtype_instance(item)

Helper function to check if an item is a string.

rl_chain.base.parse_lines(parser, input_str)

rl_chain.base.prepare_inputs_for_autoembed(inputs)

go over all the inputs and if something is either wrapped in _ToSelectFrom or _BasedOn, and if their inner values are not already _Embed, then wrap them in EmbedAndKeep while retaining their _ToSelectFrom or _BasedOn status

rl_chain.base.stringify_embedding(embedding)

langchain_experimental.smart_llm

Generalized implementation of SmartGPT (origin: https://youtu.be/wVzuvf9D9BU)

Classes

smart_llm.base.SmartLLMChain

Generalized implementation of SmartGPT (origin: https://youtu.be/wVzuvf9D9BU)

langchain_experimental.sql

Chain for interacting with SQL Database.

Classes

sql.base.SQLDatabaseChain

Chain for interacting with SQL Database.

sql.base.SQLDatabaseSequentialChain

Chain for querying SQL database that is a sequential chain.

sql.vector_sql.VectorSQLDatabaseChain

Chain for interacting with Vector SQL Database.

sql.vector_sql.VectorSQLOutputParser

Output Parser for Vector SQL 1.

sql.vector_sql.VectorSQLRetrieveAllOutputParser

Based on VectorSQLOutputParser It also modify the SQL to get all columns

Functions

sql.vector_sql.get_result_from_sqldb(db, cmd)

langchain_experimental.tabular_synthetic_data

Classes

tabular_synthetic_data.base.SyntheticDataGenerator

Generates synthetic data using the given LLM and few-shot template.

Functions

tabular_synthetic_data.openai.create_openai_data_generator(...)

Create an instance of SyntheticDataGenerator tailored for OpenAI models.

langchain_experimental.tools

Classes

tools.python.tool.PythonAstREPLTool

A tool for running python code in a REPL.

tools.python.tool.PythonInputs

Create a new model by parsing and validating input data from keyword arguments.

tools.python.tool.PythonREPLTool

A tool for running python code in a REPL.

Functions

tools.python.tool.sanitize_input(query)

Sanitize input to the python REPL.

langchain_experimental.tot

Classes

tot.base.ToTChain

A Chain implementing the Tree of Thought (ToT).

tot.checker.ToTChecker

Tree of Thought (ToT) checker.

tot.controller.ToTController([c])

Tree of Thought (ToT) controller.

tot.memory.ToTDFSMemory([stack])

Memory for the Tree of Thought (ToT) chain.

tot.prompts.CheckerOutputParser

tot.prompts.JSONListOutputParser

Class to parse the output of a PROPOSE_PROMPT response.

tot.thought.Thought

Create a new model by parsing and validating input data from keyword arguments.

tot.thought.ThoughtValidity(value[, names, ...])

tot.thought_generation.BaseThoughtGenerationStrategy

Base class for a thought generation strategy.

tot.thought_generation.ProposePromptStrategy

Propose thoughts sequentially using a "propose prompt".

tot.thought_generation.SampleCoTStrategy

Sample thoughts from a Chain-of-Thought (CoT) prompt.

Functions

tot.prompts.get_cot_prompt()

tot.prompts.get_propose_prompt()

langchain_experimental.utilities

Classes

utilities.python.PythonREPL

Simulates a standalone Python REPL.