class langchain.chains.prompt_selector.ConditionalPromptSelector[source]

Bases: BasePromptSelector

Prompt collection that goes through conditionals.

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

Raises ValidationError if the input data cannot be parsed to form a valid model.

param conditionals: List[Tuple[Callable[[BaseLanguageModel], bool], BasePromptTemplate]] [Optional]

List of conditionals and prompts to use if the conditionals match.

param default_prompt: BasePromptTemplate [Required]

Default prompt to use if no conditionals match.

get_prompt(llm: BaseLanguageModel) BasePromptTemplate[source]

Get default prompt for a language model.


llm (BaseLanguageModel) – Language model to get prompt for.


Prompt to use for the language model.

Return type


Examples using ConditionalPromptSelector