# `LangChain.Routing.PromptRoute`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.13/lib/routing/prompt_route.ex#L1)

Defines a route or direction a prompting interaction with an LLM can take.

This helps add complexity and specificity to an LLM's instructions without
using many tokens and helps avoid combining many things into a single prompt
setup. This works by letting the user's initial prompt define how the next
prompt is setup. A first pass is run on the prompt to determine which of the
provided PromptRoutes is the best match.

To better understand, let's see example of taking the user's input and
classifying what supported activity or specialty it is best matched with.

User prompt:
> Let's create a marketing focused blog post comparing three types of our
> trailer hitch products.

We want our assistant to use different prompts for the different types of
activities it's capable of doing. Let's define the activities like this:

    [
      PromptRoute.new!(%{
        name: "marketing_email",
        description: "Create a marketing focused email",
        chain: marketing_email_chain
      }),
      PromptRoute.new!(%{
        name: "blog_post",
        description: "Create a blog post that will be linked from the company's landing page",
        chain: blog_post_chain
      }),
      PromptRoute.new!(%{
        name: "support_triage",
        description: "Triage a customer support request for severity and requested resolution",
        chain: support_triage_chain
      })
    ]

Given the user's prompt and the routes we provided, it will choose
"blog_post". This leads to an LLMChain being setup for that purpose where the
user's initial prompt can be re-run against the prompts we define for that
route.

When a `chain` is linked to each route, we can specify the model to use, the
prompt templates we want, and associate functions that can be used to
accomplish the task.

The selected LLMChain can then be run through a UI for chat interactions where
the user and AI work together.

The `name` will be returned by the LLM when a particular route is selected.

The `description` is given to the LLM to help it determine if the route should
be selected based on the current input prompt.

# `t`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.13/lib/routing/prompt_route.ex#L71)

```elixir
@type t() :: %LangChain.Routing.PromptRoute{
  chain: term(),
  description: term(),
  name: term()
}
```

# `get_selected`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.13/lib/routing/prompt_route.ex#L114)

```elixir
@spec get_selected(route_name :: String.t(), [t()]) :: nil | t()
```

Return the selected route based on the route name.

# `new`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.13/lib/routing/prompt_route.ex#L84)

```elixir
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
```

Build a new PromptRoute struct.

# `new!`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.13/lib/routing/prompt_route.ex#L95)

```elixir
@spec new!(attrs :: map()) :: t() | no_return()
```

Build a new `PromptRoute` struct and return it or raise an error if invalid.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
