Module 1 - Lesson 3d: Extended Prompts
Detailed context and instructions for advanced prompt engineering.
Published: 1/3/2026
Example 4: Extended Prompts
Extended prompts provide detailed context, specific instructions, and multiple requirements. This is where prompt engineering really shines.
What It Does
Uses a detailed system prompt with specific instructions and a complex user request with multiple criteria. Shows how to get precise, tailored responses.
Code Snippet
Create src/extended-prompt.ts:
import OpenAI from "openai"; import dotenv from "dotenv"; dotenv.config(); const openai = new OpenAI(); async function extendedPrompt(): Promise<void> { try { console.log("Testing OpenAI connection..."); const response = await openai.responses.create({ model: "gpt-5-nano", input: [ { role: "system", content: "You are a helpful travel assistant. Provide detailed travel suggestions based on user preferences and give a guide to the destination and include distance from the airport.", }, { role: "user", content: "Suggest a travel destination within Europe where there is a Christmas market that is famous but is not in a big city. I would like to go somewhere that is less than 2 hours from a major airport and has good public transport links.", }, ], }); console.log("✅ Basic Prompt Success!"); console.log("AI Response:", response.output_text); console.log("Tokens used:"); console.dir(response.usage, { depth: null }); } catch (error) { if (error instanceof OpenAI.APIError) { console.log("❌ API Error:", error.status, error.message); } else if (error instanceof Error) { console.log("❌ Error:", error.message); } } } extendedPrompt().catch(console.error);
Run It
pnpm tsx src/extended-prompt.ts
Key Points
- Detailed system prompt: Sets clear expectations
- Specific user requirements: Multiple criteria in one request
- Better results: More context = better, more relevant answers
- Use case: Complex queries requiring specific information
Tips for Extended Prompts
-
Be specific about format:
content: "Provide a list with: destination name, distance from airport, and transport options."; -
Include constraints:
content: "Must be in Europe, less than 2 hours from airport, not a major city."; -
Request structure:
content: "Format your response as: 1) Destination, 2) Why it fits, 3) Practical details.";