Skip to main content
All CollectionsAdvanced Features
How to use prompt chaining
How to use prompt chaining

Everything you need to know to get started with Promptchains in

Dan Cleary avatar
Written by Dan Cleary
Updated over 3 months ago

Chains in PromptHub make it easy to take the output from one prompt and feed it into the variable value of a later prompt.

Before diving into examples, here are some of the basics

Chains basics

  1. Commit Requirement: You can only use projects that have commits. To include a project in a chain, you must first create it from the library page and then commit a prompt. Once committed, you’ll be able to select it from the dropdown menu.

  2. Head Prompt: The last committed prompt (also known as the "head") will run as a link in the chain.

  3. Variables: For chains to be useful, your projects should include at least one variable. (more on how to use variables here).

Inserting the output from one project as the input to another

You can send the output from one link in the chain as an input to a variable in any downstream link, not just the next one.

For example, you can send the output from Step 1 as an input value in Step 3.

You can inject the output into a variable value in one of two ways

By typing: Use the following syntax to inject the output of one step into a variable value:{{step.n.output}}, where n is the number of the step in the chain that you wish to use.

By using the inject action: In the action column, click the icon shown below to automatically inject the output from the previous step into a variable value.

Examples

We'll create two prompt chains

  1. A chain that generates a LinkedIn post and then "translates" it to sound like a pirate

  2. A prompt chain that uses least-to-most prompting

Example 1: Pirate LinkedIn Post Generator

Step 1 - Create project and commit

I already have a LinkedIn post generator project, so I'll quickly create a "Content Remixer" project with a prompt that takes a text input and rewrites it to sound like a cowboy.

I tested it a few times and then committed this version above^.

Remember, in order to use this prompt in any chain, there needs to be at least one commit.

Step 2 – Spin Up the Prompt Chain

Now, let's set up the prompt chain by inserting the output from my LinkedIn post generator prompt as the input to the Content Remixer prompt.

Step 3 – Run the Chain

Click "Run Chain" at the top of the page, and we're done!

Looks good to me!

Example 2: Automate least-to-most prompting

Least-to-most prompting breaks down complex problems into a series of simpler subproblems that get executed sequentially. There are two stages:

  1. Decomposition step: Breaks down the problem into a list of subproblems. This prompt includes few-shot examples.

  2. Subproblem solving step: The subproblems are solved in sequence.

We'll use three prompts:

  1. Generate Few-Shot Examples: Create examples of problems and subproblems for any type of task.

  2. Decompose the Task: Using the few-shot examples generated, decompose the specific task at hand.

  3. Solve Subproblems: Pass the generated subproblems and solve them sequentially.

We have templates for each prompt so you can use them right away.

Task Example: Customer Service Question

"I recently purchased a T-shirt from your Transport collection on November 1st. It was originally priced at $25, but I bought it at a 40% discount. I noticed you now have a 50% discount on shirts. Can I return the shirt and use the store credit to buy two shirts at the new discount rate?"

Step 1 - Generate dynamic few-shot examples

Link to template

Step 2 - Decompose the problem

Link to template

Step 3 - Solve the subproblems sequentially

Link to template

Final Chain Workflow:

  1. Generate Few-Shot Examples: Based on the customer service question.

  2. Decompose the Question: Use the examples to teach the model how to break down the question into subproblems.

  3. Execute Subproblems: Solve each subproblem sequentially.

And here is the output:

T‍he cool part is that this chain can be used for any type of problem!


Did this answer your question?