3 Writing the right prompt
The chapter explains that writing the right prompt is the most important skill for building successful GenAI applications. Prompt engineering is presented as both a science, because it follows clear principles and proven frameworks, and an art, because natural language is flexible and requires experimentation, creativity, and iteration. The core message is that an LLM cannot read minds, so the quality of the output depends heavily on how clearly and thoughtfully the prompt is written.
A good prompt needs the right length and structure. If it is too short, the model lacks context and may hallucinate; if it is too long or cluttered, the model may misread what matters most, and it can also run into context-window limits. The chapter proposes a practical four-part template for strong prompts: define the role the model should play, specify the task clearly, state the desired features of the output, and provide examples. It also shows how techniques like double-down, giving the model an escape hatch, breaking tasks into steps, asking for chain-of-thought reasoning, and self-validation can improve reliability and precision.
The chapter then shows how to apply these ideas in Langflow using prompt templates and variables, making prompts reusable and easy to compose from multiple parts. It demonstrates building conversational memory by combining the latest user message with chat history, and it walks through a two-step “Healthy Chef” flow where one model acts as a chef and another as a dietitian to refine the result. The overall lesson is that effective prompt design is iterative and practical: start simple, add structure and examples, test the response, and keep refining until the output becomes truly useful.
Like pirates, GenAI might also get hallucinations.
The standard prompt template in action—for a thoughtful daughter.
The more examples you give the LLM, the easier the climb
Role, Task, Features, and Examples: elementary, dear Watson!
This drink better be magic.
To give memory to our LLM, we shall combine the user message with the conversation history.
We equip LLMs with memory by sending them the whole history every time.
Design your prompt in style with the Prompt Template component.
The Prompt Template component has one input connector for each required variable.
Our Pirate Assistant 2.0 may still drink rum non-stop but now remembers conversations!
Chef vs. Dietitian: one generates, the other refines.
The chef–dietitian combo didn’t quite work out for the user.
You can check how the chef behaves by running the first part of the flow.
A decadent dark chocolate cake with raspberry ganache. Not bad, chef, not bad.
Typical of dietitians. Never trust them around cakes.
The Healthy Chef™ flow. A GenAI app designed to help users balance enjoyment and health.
Summary
- A prompt is the input received by an LLM that generates the corresponding output, serving as the foundation of all GenAI applications.
- The standard prompt template, with its four parts—role, task, features, and examples—helps create well-structured prompts that provide clarity and precision to guide the LLM effectively.
- Prompt enhancement techniques, including "double-down," "breaking the task down," "chain-of-thought," "self-validation," and "giving the LLM a way out," significantly improve the quality and reliability of responses.
- Langflow allows users to build GenAI workflows by connecting modular components, such as inputs, prompts, and LLMs, to create complex systems with minimal effort.
- The Healthy Chef™ flow showcases how adversarial roles, like a Chef and Dietitian, can collaborate through structured prompts to produce creative and healthier recipes.
Grokking AI Applications ebook for free