Skip to main content

Prompt Chaining

Prompt chaining is a powerful technique that allows you to connect multiple prompts in sequence, where the output of one prompt becomes the input for the next. This enables complex data processing workflows and multi-step analysis.

How Prompt Chaining Works

In prompt chaining, you can:

  • Pass extracted data from one prompt to another
  • Build complex processing pipelines
  • Create sequential analysis workflows
  • Transform data through multiple stages

Prompt Chaining Scenarios

There are two main scenarios for how data flows between chained prompts:

1. Direct Value Passing

The raw output from the first prompt is directly sent as input to the second prompt without any modifications using the syntax: {{prompt_key}}

2. Processed Value Passing

The output from the first prompt undergoes processing through a post-processing URL before being sent to the next prompt using the syntax: {{[prompt_key] <post_processing_url>}}

Examples

Example 1: Direct Value Passing

In this scenario, the extracted value is directly sent from one prompt to the next without any intermediate processing.

Scenario: Direct sending the values

Syntax: {{prompt_key}}

First Prompt key: transaction_amount

What is the amount for the transaction named "SAFEWAY" is processed. Reply only the amount

Direct Result: 23.11

Second Prompt key: transaction_date

What is the transaction date for this {{transaction_amount}}

Flow:

  1. First prompt extracts: 23.11
  2. Value 23.11 is directly passed to the second prompt
  3. Second prompt uses {{transaction_amount}} = 23.11 to find the transaction date
  4. Final result: 09/30/23

Prompt Chaining Example 1

When to use Direct Value Passing When:

  • You need to preserve the exact format of extracted data
  • The next prompt requires the raw, unmodified value
  • Building simple sequential queries
  • Maintaining data integrity is crucial

Example 2: Processed Value Passing

In this scenario, the extracted value is processed/transformed before being sent to the next prompt or external system.

Scenario: Sending the value after processing

Syntax: {{[prompt_key] <post_processing_url>}}

First Prompt: transaction_amount

What is the amount for the transaction named "SAFEWAY" is processed. Reply only the amount

Initial Result: 23.11

Second Prompt: amount

print this {{transaction_amount}}https://webhook.site/28656756-3c25-4e57-8ad0-4896e64581a2}}

Processing Stage:

{
"value": "23.11",
"new_value": "33.11"
}

Flow:

  1. First prompt extracts: 23.11
  2. Value undergoes post-processing (adds 10 to original value)
  3. Processed result: 33.11
  4. Processed value can be used in subsequent prompts

Prompt Chaining Example 2)

When to use Processed Value Passing When:

  • You need to transform or enrich the data
  • Performing calculations on extracted values
  • Integrating with external systems via webhooks
  • Adding business logic between prompts
  • Formatting data for specific requirements