How to Write a Great Prompt for ChatGPT
Master the art of prompt engineering with our comprehensive guide, based on the latest research and best practices.
What is Prompt Engineering?
Prompt engineering is the art of designing optimal instructions (prompts) to guide a large language model (LLM) towards high-quality responses. Mastering this skill has become essential to fully leverage models like GPT-4, Claude, or PaLM, whether for individual tasks (writing, summarizing, classifying, data extraction, rewriting, translation, etc.) or when orchestrating conversational agents with system instructions. This guide presents updated best practices for 2025 based on reliable sources (OpenAI, Anthropic, Google) and recent findings.
Master Template for Professional Prompts
A well-structured prompt facilitates model comprehension and produces more consistent results. It is recommended to use a template with clear sections, even using markers or tags to distinguish each part. This helps the model not confuse instructions, context, or examples. Below, we present a general reusable template that can be adapted to different use cases:
Define the model's role/personality here if useful (optional). E.g.: 'You are an expert data analyst...'
Describe the task to be performed **clearly, specifically, and in detail**. Include the desired response format (list, paragraph, JSON, etc.), expected length, style or tone, and any important criteria. E.g.: 'Summarize the text in 3 concise bullet points, in a formal tone, highlighting only key facts.'
Provide any **relevant context or input text** that the model should use. Clearly separate this content, for example with delimiters like ```"""``` or XML tags, so the model differentiates instructions from the text.
**Optional:** If *few-shot prompting* applies, include **examples** of expected inputs and outputs to guide the model. Each example should follow the desired format and correctly illustrate the task. Separate examples from the rest of the prompt with a clear marker (e.g., `##` between examples).
**Optional:** If required, specify an expected **output format** template here. For example, you can show empty fields or JSON that the model should fill, or XML tags like `<respuesta></respuesta>` to delimit the response.
As seen, this template uses descriptive <...> markers (role, instructions, context, etc.) as structured comments. In practice, you can use placeholders or variables for dynamic parts, which facilitates reusing the prompt in multiple calls. For example, Anthropic suggests double curly brace notation {{variable}} for variable content. A simple template example with a variable would be: 'Translate this text from English to Spanish: {{text}}'. Separating sections this way ensures the model correctly interprets which part is instruction and which part is input data.
General Best Practices in Prompt Engineering
Clearly state what you want, avoiding ambiguities. Specify the context, expected outcome, format, and style in the initial instruction itself. A vague prompt produces vague responses; conversely, a detailed prompt guides the model with greater precision. For example, instead of asking 'Write about OpenAI', it would be better to say 'Write a brief article (3 paragraphs) about OpenAI's impact on the tech industry, with an optimistic and informative tone'.
First indicate what the model should do, then provide the necessary data or text. Use clear delimiters (e.g., ###, """, XML tags) to separate instructions from input content, especially in tasks like summarization or extraction. This helps the model not mix instructions with the text to be processed.
If the task depends on certain information or context, include it in the prompt. A good prompt will frame the problem: What is it about? What data or situation does the model have? For example, before asking a question about a text, present that text under a <contexto> section or tell it 'Text: ...'. This increases the relevance and accuracy of the response.
Explicitly state how you want the response. If you expect a bulleted list, a JSON table, or a certain length, say so in the prompt. Example: 'Return only the names in a bulleted list' or 'Respond in a maximum of 2 sentences'. The more concrete you are about the format, the less 'guessing' the model will have to do, leading to more consistent outputs.
Instead of only saying what the model should *not* do, indicate what it *should* do. Absolute negatives can be misinterpreted or ignored. For example, instead of 'Do not use an informal tone', state 'Use a professional and formal tone (avoid colloquialisms)'. This establishes a clear guide without leaving ambiguous spaces.
Do not overload the prompt with unnecessary verbosity or contradictory instructions. A simple and focused prompt usually performs better. Use action verbs and direct language (p. ej. 'Solve...', 'List...', 'Analyze...'). Eliminate vague instructions like 'make it pretty' or 'be creative' without further context, as they are imprecise. If you want creativity, specify it better: 'propose a creative analogy' instead of 'be creative'.
If your request is very complex, consider dividing it either into sequential sub-prompts (chaining) or internally in the formulation. You can ask the model to 'think step by step' before responding. For example: 'First analyze the problem and list possible solutions, then provide the best solution with its reasons.' Google recommends breaking down complex tasks for better quality in each part. In a multi-turn environment, you can also chain messages: first get a plan or a list, then ask for details on a point, etc., instead of everything at once.
Consider prompt engineering as an iterative process. If the first response is not optimal, adjust the wording, add more detail or clarify instructions, and try again. Small changes (adding a context sentence, adjusting the requested tone, etc.) can produce notable improvements. Document versions of your prompts and compare results to see which formula works best.
A well-designed prompt should work robustly, but always test with the desired target model (GPT-4, Claude 2, etc.). Different models (or new versions) may interpret prompts differently. For example, a prompt that works in GPT-3 may require adjustments in GPT-4 due to its more advanced reasoning capabilities. When changing models or when a provider releases an update, re-validate your key prompts.
Advanced Techniques and Expert Hacks
In addition to general best practices, experts from OpenAI, Anthropic, Google, and the community have developed special techniques (hacks) for more difficult use cases. These techniques can further enhance the quality of responses:
Consists of providing input-output examples within the prompt for the model to learn the desired pattern. For example, if you want to classify sentiments, you can give a couple of text examples and their classification *before* asking for the new text. OpenAI advises trying first without examples (zero-shot), and if the result is not good, then add 1-3 relevant examples (one-shot/few-shot). Examples should be *representative and varied*, showing exactly the expected output format. Be careful not to give too many very specific examples, as it could over-adjust the model's response to those cases (overfitting). With 2-5 examples, it is usually enough to improve the response while maintaining generality.
This is a technique where the model is instructed to 'think step by step' instead of directly giving the answer. This can be done implicitly (adding the phrase 'Reflect step by step...' or 'Let's think step by step' before the response) or explicitly by asking it to show its reasoning. Several studies have shown that inducing a chain of thought improves the ability to solve complex or multi-step problems. For example, Anthropic suggests using `<Thinking>` tags for Claude to first write its deductions, and then `<answer>` for the final response. This even allows separating and hiding internal reasoning if it is not desired to show it to the end-user. Note: For very advanced reasoning models (like GPT-4), it is sometimes not necessary to indicate this, as they already tend to break down the problem internally. Google recommends using CoT with simple prompts and not forcing it if the model already reasons well on its own.
Structuring both the prompt and the output in XML, JSON, or another delimited scheme can provide more control. Anthropic reports that using tags like `<instructions>...</instructions>` for instructions, `<data>...</data>` for data, `<example>...</example>` for examples, etc., prevents the model from mixing roles. Likewise, in the output, asking for responses in, for example, JSON format with specific fields, or within `<response>...</response>` tags, helps to easily extract information and reduces variability in presentation. This technique combines well with few-shot: you can provide an example with the exact desired format for the model to imitate.
It is useful to start the prompt by defining who the model is in the context of the task, which acts as a kind of injected system prompt. For example: 'You are the world's best copywriter, specialized in a humorous but professional tone...'. This leverages the model's ability to follow a specific character or set of knowledge. In chat environments with system messages, place these role instructions in the system message to keep them persistent. A well-defined role can lead to more coherent and domain-appropriate responses (the model will act 'as an expert' instead of a generalist). Combine this with clear instructions in the user message for optimal results.
Another hack is to start the model's response within the prompt to set the tone or structure. For example, include at the end of the prompt a line that simulates the beginning of the response: 'Assistant:[responds in a formal tone]...'. Similarly, you can provide an empty response schema that the model should fill, such as a bulleted list already started (- ) or section titles already written for a report. This pre-formatting serves as a strong guide and reduces doubts about how to start the response.
For complex tasks, consider an agent approach where the model works in several steps instead of a single prompt. You can have the model generate a plan first, then feed that plan back with another question. Also, if you have tool functionality (e.g., through APIs that allow the model to search for information, perform calculations, etc.), structure the prompt to integrate them. A known pattern is ReAct, where the model alternates reasoning and actions in the prompt to solve problems step by step. For this, prompts are designed with sections like 'Thought: ...', 'Action: ...', controlling that the model follows the format. These approaches transcend the single prompt and use extensive system prompts to define the agent's operating mode, including possible tools and how to use them. They are useful in products where the AI is required to act autonomously following certain rules.
Suggested Parameters for LLMs
Apart from the prompt content, the model's configuration parameters play a crucial role in the quality and style of the output. Some general recommendations:
Use the most capable model available for the task within your possibilities. Newer models tend to follow instructions with greater fidelity and require less prompt tweaking. Note: More powerful models are usually more expensive and slower, so balance cost-benefit according to the case.
Controls randomness vs. determinism in generation. High temperature (~0.7–1.0) produces more creative and varied responses, useful for original writing or brainstorming tasks. Low temperature (~0–0.3) produces more focused and repeatable outputs, ideal for factual tasks, extraction, or when consistency is needed. OpenAI suggests using temperature 0 for strictly precise or data-driven responses as it minimizes data invention.
Sets an upper limit of tokens in the response. It does not guarantee that the model will write up to that limit or stop before if it doesn't reach it, but it serves to cut overly long responses. Set it high enough not to truncate useful content; then, control length primarily through instructions in the prompt (e.g., 'no more than 200 words').
Are text strings at which generation will stop if they appear. For example, you can use '\nUser:' as a stop if you want the model to stop before starting to simulate the user in a chat environment. Configure these sequences to avoid unwanted overflows after the response is complete.
Depending on the model/API, there are other settings. Top-p (nucleus sampling) is an alternative or complement to temperature that limits vocabulary to X% of accumulated probability; it's often used to fix one (e.g., top_p=1) and only play with temperature, or vice versa. Frequency penalty and presence penalty (in OpenAI) prevent excessive repetitions by penalizing the model if it repeats words or phrases already said. A moderate value in these penalties can improve listings or avoid filler words in the response. In general, experiment with these parameters one by one to see their effect, or consult provider recommendations for the specific task.
Although not a numerical parameter, it's worth mentioning configuring the format appropriately. For example, in the OpenAI API when using Chat Completion, leverage the `system message` field for global instructions (role, style) and leave the `user message` for the specific request. Some environments allow forcing Markdown format in the output, which is useful if you want well-rendered tables or lists. If your digital product requires the response in HTML, CSV, or another format, indicate it in the prompt and be prepared for minimal post-processing (e.g., JSON decoding). The key is to ask the model to produce a format easy to integrate into your workflow (many prompt engineers ask 'Return the response only as valid JSON with fields X, Y...' to save parsing work).
How to Avoid Common Errors
Even following best practices, there are typical failures in prompt construction. Here are some common errors and how to avoid them:
An ambiguous prompt produces ambiguous responses. Avoid general terms or open-ended questions without sufficient context. Solution: Specify key details: who, what, how, and by what criteria the model should respond. For example, 'Summarize the article' is ambiguous (what length? what focus?), better 'Summarize the following article in 5 sentences highlighting the most controversial points'.
If you provide examples (few-shot), ensure they do not contradict instructions or each other. All should follow the desired format and criteria. An error would be to ask for 'brief responses' but show long paragraphs in the examples. Solution: review that the examples exactly model the result you are asking for. If you change instructions, update examples to maintain consistency.
Saying 'do not do X' without clarifying 'do Y instead' can confuse the model. For example: 'Do not give recommendations' could lead the model to end abruptly or ignore the instruction. Solution: rephrase the rules positively. In this case: 'Limit yourself to stating facts without including recommendations'. This way the model knows what to do instead of just what to avoid.
Occurs when the prompt is too brief for the complexity of the task. The model fills in the gaps as best it can, sometimes incorrectly. Solution: add the missing information. If the task requires assuming a context (domain, target audience, output format), it is better to provide it than to expect the model to guess. For example, if you want advertising text, specify the audience ('young clients', 'B2B executives') to guide the tone.
This is the opposite: flooding the model with indications, examples, and restrictions can be counterproductive. Excessively long or rigid prompts can stress the model (leading it to strive to comply with everything to the letter, sometimes failing at basic things). They also increase token cost. Solution: find a balance. Include enough detail, but *only what is necessary* to achieve the desired response. Do not saturate with 10 examples if 2 are enough. Do not repeat the same instruction in different words. Avoid irrelevant data that could distract (the model might accidentally use them). A prompt should be complete but concise.
A prompt can behave differently in another language or model. Solution: if you are going to use the prompt in several languages (e.g., sell it in a bilingual package), test it in each target language. Adjust cultural or vocabulary nuances. For example, certain tones (humor, politeness) are achieved differently in Spanish than in English. It may be useful to include an explicit language instruction in the prompt: 'Respond in neutral Spanish'. Also, adapt the prompt to the model's idiosyncrasies; e.g., models like GPT tend to verbosity, so it is advisable to ask 'be concise', while others may require being encouraged to give more detail.
Examples of Well-Designed Prompts
The model is asked to provide an executive summary in bullet points of a provided text, adopting a specific role.
Prompt:
<rol> You are **TechGPT**, an AI assistant expert in financial technology. Your job is to analyze texts and extract key insights for a business audience. </rol>
<instrucciones> **Task:** Read the article below and **provide a concise executive summary** in **3 bullet points**. Focus on the **most important facts and conclusions**, avoiding any irrelevant details. Use a **formal, informative tone** as this summary is for senior managers. </instrucciones>
<contexto> **Article:** """The fintech industry grew 200% in 2024... (here would go the full article text)""" </contexto>
<salida> **Output Format:**
-Bullet 1: <summary point>
-Bullet 2: <summary point>
-Bullet 3: <summary point> </salida>Why it works:
This prompt starts by defining an *expert role* (TechGPT) to guide the model's style and knowledge. Then, in the *instructions* section, it details the task ('executive summary'), format (3 bullet points), focus (key facts and conclusions), and tone (formal for managers), fulfilling the recommendation to be specific about outcome and style. The *context* is provided clearly delimited with `"""` so the model knows which text to summarize. Finally, an *expected output format* is shown with numbered bullet points, serving as an explicit guide. The model, by following this prompt, will tend to deliver exactly 3 well-focused bullet points, thanks to the clarity and structure of the message.
The model is asked to extract key data from a contract and respond in JSON.
Prompt:
<rol> Eres un asistente legal inteligente especializado en análisis de contratos empresariales. </rol>
<instrucciones> Extrae la **siguiente información** del contrato a continuación:
1.`partes` – Nombres de las partes involucradas.
2.`fecha_firma` – Fecha en que se firma el contrato.
3.`obligaciones_principales` – Lista breve de las obligaciones principales de cada parte.
4.`cláusulas_riesgos` – Cualquier cláusula que represente riesgos legales (resumen corto).
Devuelve **únicamente** la respuesta en formato **JSON**, utilizando esos campos exactos como claves. No incluyas explicación adicional. </instrucciones>
<contexto> **Contrato:**
"""CONTRATO DE SERVICIO
Entre ACME S.A. (en adelante, "Proveedor") y Industrias XYZ S.L. (en adelante, "Cliente")
Fecha: 5 de enero de 2025
... [texto completo del contrato] ...
Cláusula 7: Responsabilidad Limitada ..."""
</contexto>Why it works:
En este prompt en español, se especifica primero el *rol* (un asistente legal especializado) para darle al modelo un contexto de experto. Las instrucciones enumeran claramente qué datos extraer, usando una lista numerada que delimita cada elemento requerido. Esto reduce ambigüedad y segmenta la tarea compleja en sub-tareas claras. Se indica explícitamente el formato *JSON* deseado y que no añada nada más, cumpliendo con la práctica de *formato específico* y *lenguaje positivo* ('devuelve únicamente...') en lugar de solo decir 'no hagas...'. El *contexto* proporciona el texto del contrato entre triple comilla, para separar nítidamente el contenido legal de las instrucciones. Gracias a esta estructura, el modelo sabrá exactamente qué buscar en el contrato y cómo formatear la respuesta.
Conclusion
By following this guide of best practices, it is possible to create highly effective prompts that act as valuable assets in digital products. The provided master template serves as a flexible starting point for designing professional prompts, while advanced techniques (few-shot, chain-of-thought, roles, structuring with tags, etc.) allow fine-tuning the interaction with LLMs to obtain premium results. Finally, adjusting model parameters and being aware of common errors will prevent setbacks and ensure that prompts produce coherent, accurate content tailored to specific needs, whether in English, Spanish, or any other language. With practice and iteration, prompt engineering becomes a powerful tool to convert the general capabilities of a model into tailored responses for our objectives.
Ready to Master Prompt Engineering?
Our Professional Prompt Packs and Bundle provide expertly crafted prompts to kickstart your AI productivity.