# 4.1. Prompt Chaining

In the context of large language models (LLMs), prompt chaining refers to a technique where multiple prompts are chained together to generate a sequence of outputs from the model. The idea behind prompt chaining is to enable the model to generate longer sequences of text or to perform more complex tasks by breaking them down into smaller sub-tasks, each of which can be handled by a separate prompt.

Prompt chaining can be achieved in various ways, such as:

1. Serial prompting: This involves providing the model with a sequence of prompts, one after the other, where each prompt builds upon the previous one. For example, a first prompt might ask the model to generate a list of items, and a second prompt might ask the model to describe each item on the list.
2. Hierarchical prompting: This involves using a hierarchical structure of prompts, where a high-level prompt is broken down into lower-level prompts, each of which is further refined until the task is completed. For example, a high-level prompt might ask the model to write a story, and lower-level prompts might ask the model to generate characters, plot points, and sentences.
3. Hybrid prompting: This combines serial and hierarchical prompting techniques to create a hybrid approach. For example, a high-level prompt might ask the model to generate a report, and lower-level prompts might ask the model to provide data analysis, charts, and tables for the report.
4. Self-prompting: This involves training the model to generate its own prompts based on the input it has received so far. This allows the model to continue generating output even when the human-provided prompts run out.

By chaining prompts together, LLMs can generate longer sequences of text or perform more complex tasks than they would be able to do with a single prompt. However, it's important to note that prompt chaining can also introduce new challenges, such as ensuring that the prompts are well-coordinated and that the model doesn't get stuck in an infinite loop. Researchers are actively exploring different approaches to address these challenges and improve the effectiveness of prompt chaining in LLMs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.legalpromptguide.com/4.-ethical-guardrails-and-professional-responsibility/4.1.-prompt-chaining.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
