Introduction
Artificial intelligence is changing how we learn, work, write, and solve problems. Tools powered by Large Language Models (LLMs) can generate text, answer questions, summarize documents, classify messages, and even produce structured data. However, the quality of their responses often depends on how we communicate with them.
This is where Prompt Engineering becomes important.
Prompt engineering is the process of designing clear and effective instructions that guide an AI model towards a useful and relevant response. Instead of asking a vague question and accepting the first answer, we learn to provide context, examples, constraints, and an expected output format.
For developers, students, researchers, and businesses, this skill can make AI applications more reliable and easier to use.
In this article, we will explore five practical prompt engineering techniques and examine real experiments conducted using Google Gemini through Google AI Studio.
What Is Prompt Engineering?
A prompt is the instruction or input provided to an AI model. It can be a question, a command, a piece of text, or a combination of information and instructions.
Prompt engineering involves improving that input so the model understands the task and produces an output that matches the requirement.
Consider the following example:
Vague prompt:
“Explain machine learning.”
Improved prompt:
“Explain machine learning to a beginner in simple English. Describe supervised, unsupervised, and reinforcement learning, and provide one practical example of each. Keep the explanation under 300 words.”
The second prompt provides context, audience, scope, and output requirements. This reduces ambiguity and gives the model a clearer direction.
Prompt engineering does not guarantee that an AI model will always produce a correct answer. However, it helps us communicate requirements more precisely and evaluate whether the response meets our expectations.
5 Important Prompt Engineering Techniques
1. Zero-Shot Prompting
Zero-shot prompting means asking an AI model to perform a task without providing examples of the expected answer.
The model receives an instruction and uses its existing capabilities to complete the task.
Example prompt:
“You are a customer support classification assistant. Classify the following message into one of these categories: Billing, Technical Issue, Account Access, or General Inquiry.
Message: I was charged twice for my monthly subscription.”
Expected output:
Billing
Zero-shot prompting is useful when the task is straightforward and the categories or expected behaviour can be explained clearly.
Common applications include:
- Customer support message classification.
- Sentiment analysis.
- Text summarization.
- Basic information extraction.
2. Few-Shot Prompting
Few-shot prompting provides a model with a small number of examples before asking it to perform a new task.
These examples demonstrate the pattern the model should follow.
Example prompt:
Classify customer messages into the correct category.
Examples:
- “My credit card was charged twice.” → Billing
- “The mobile application keeps freezing.” → Technical Issue
- “I cannot reset my password.” → Account Access
- “What are your company’s working hours?” → General Inquiry
Now classify:
“My account was locked after several unsuccessful login attempts.”
Expected output:
Account Access
Few-shot prompting is especially useful when the task requires a particular format, classification pattern, tone, or style.
The quality of examples matters. Examples should represent the different situations the model may encounter rather than repeatedly demonstrating only one type of input.
3. Step-by-Step Prompting
Some tasks require multiple calculations or logical operations. Asking for only the final answer may make it difficult to understand how the model reached its conclusion.
Step-by-step prompting asks the model to present the important stages of a solution in an organized way.
Example prompt:
“A company purchases 120 laptops at ₹35,000 each. It sells 75 laptops at a profit of 20% and the remaining laptops at a loss of 10%.
Calculate the overall profit or loss percentage. Show the total cost price, selling price of both batches, total selling price, and final profit or loss calculation.”
This approach is useful for:
- Mathematical problems.
- Data analysis explanations.
- Technical troubleshooting.
- Breaking complex tasks into smaller stages.
An important point is that a detailed explanation does not automatically mean the answer is correct. Calculations and important claims must still be checked independently.
4. Structured JSON Prompting
AI models often return information in natural language. However, software applications frequently need predictable data formats that can be processed by programs.
Structured JSON prompting asks the model to return information using a defined JSON structure.
Example prompt:
“Extract the person’s name, date, amount, and currency from the following sentence. Return valid JSON only. Use YYYY-MM-DD for dates, a numeric value for the amount, and a three-letter ISO currency code. If a field is unavailable, use null.”
Input:
“John ordered a product for $75, but the payment date was not mentioned.”
Expected output:
{
"name": "John",
"date": null,
"amount": 75,
"currency": "USD"
}
This technique is useful in:
- API integrations.
- Data extraction pipelines.
- Chatbot development.
- Database operations.
- Automated document processing.
One important distinction is that valid JSON does not necessarily mean correct information. A response may follow the required structure but still contain an incorrect value. Both syntax and extracted data must be validated.
5. Clear Instructions and Constraints
A good prompt should explain exactly what the model needs to do and what it should avoid doing.
Useful instructions include:
- Define the model’s role.
- Explain the task clearly.
- Provide relevant context.
- Specify the expected response format.
- Set limits on length or scope.
- Explain how missing information should be handled.
For example, instead of asking:
“Extract the details from this message.”
Use:
“You are an information extraction assistant. Extract the person’s name, transaction date, amount, and currency. Return exactly four JSON keys. Do not guess missing information. Use null when a value is not available.”
Clear constraints are particularly important when building AI-powered applications where responses are consumed by other software systems.
Practical Experiments Using Google Gemini
To understand how these techniques work in practice, I conducted three experiments using Google Gemini through Google AI Studio.
The experiments focused on classification, mathematical problem-solving, and structured data extraction.
Experiment 1: Zero-Shot vs Few-Shot Classification
Objective: Compare how zero-shot and few-shot prompts perform when classifying customer support messages.
I selected four categories:
- Billing
- Technical Issue
- Account Access
- General Inquiry
A dataset of eight customer messages was prepared. The messages covered situations such as duplicate subscription charges, application crashes, password problems, refund updates, server errors, locked accounts, and student discounts.
First, I tested the messages using a zero-shot prompt without providing examples. Next, I used a few-shot prompt containing four classification examples.
Observed results:
| Technique | Correct predictions | Accuracy |
|---|---|---|
| Zero-shot | 8/8 | 100% |
| Few-shot | 8/8 | 100% |
Both approaches classified all eight messages correctly.
The few-shot prompt did not improve accuracy because the zero-shot prompt had already achieved 100% on this small dataset. However, the experiment demonstrated how examples can be included to communicate the expected classification pattern.
This result should not be treated as proof that both techniques will always perform equally well. A larger and more diverse dataset would be needed for a stronger comparison.
Experiment 2: Direct Prompting vs Step-by-Step Prompting
Objective: Examine how different instructions affect the explanation of a mathematical problem.
The problem involved a company purchasing 120 laptops at ₹35,000 each. It sold 75 laptops at a 20% profit and the remaining 45 laptops at a 10% loss.
I tested two approaches:
- Direct prompting: Asked Gemini to calculate the overall profit or loss percentage.
- Step-by-step prompting: Explicitly requested the cost price, selling price of each batch, total selling price, and final calculation.
Reference calculation:
Total Cost Price:
120 × ₹35,000 = ₹42,00,000
Selling Price of the first batch:
75 × ₹42,000 = ₹31,50,000
Selling Price of the second batch:
45 × ₹31,500 = ₹14,17,500
Total Selling Price:
₹31,50,000 + ₹14,17,500 = ₹45,67,500
Overall Profit:
₹45,67,500 − ₹42,00,000 = ₹3,67,500
Profit Percentage:
(₹3,67,500 / ₹42,00,000) × 100 = 8.75%
Observed results:
Both approaches produced the correct final answer: an overall profit of 8.75%.
The direct prompt also generated a detailed explanation, while the step-by-step prompt followed the requested stages more explicitly.
The experiment showed that specifying the expected structure can make an explanation easier to follow. However, since both approaches produced the same correct answer in this single test, it does not establish that step-by-step prompting is generally more accurate.
Experiment 3: Structured JSON Output
Objective: Test whether Gemini can extract information from natural-language messages and return it in a consistent JSON format.
The required fields were:
namedateamountcurrency
The date had to follow the YYYY-MM-DD format, the amount had to be numeric, and the currency had to use a three-letter ISO code. Missing information had to be represented using null.
Five different test messages were used, including examples involving Indian rupees, US dollars, and euros. One test intentionally omitted the payment date.
Observed results:
| Evaluation | Result |
|---|---|
| Valid JSON responses | 5/5 |
| All required keys present | 5/5 |
| Fully correct extractions | 4/5 |
| JSON syntax success | 100% |
| Full extraction correctness | 80% |
In the first test, Gemini returned the Indian rupee symbol (₹) instead of the required ISO currency code (INR). The JSON itself was valid, but the currency field did not follow the specified convention.
In the remaining tests, the model returned the expected currency codes and extracted the available information correctly. It also represented the missing payment date in the fifth test using null, rather than inventing a date.
This experiment highlighted an important lesson: structured output requires more than valid syntax. Applications should validate both the JSON structure and the meaning of its values.
Note: The prompts were refined during the five tests, so this experiment evaluates the observed outputs rather than proving that one fixed prompt configuration will achieve the same results in every situation.
Key Learnings from the Experiments
These practical experiments helped demonstrate several important points about prompt engineering:
- Clear instructions matter: A well-defined task gives the model less room to misunderstand the requirement.
- Examples can guide outputs: Few-shot prompting demonstrates the pattern expected from the model.
- Output structure improves readability: Step-by-step instructions can make complex explanations easier to inspect.
- Valid JSON is not enough: Data must also follow the expected types, formats, and values.
- Testing is essential: Prompt quality should be evaluated using actual outputs instead of assumptions.
The experiments also showed why small test results should be interpreted carefully. A model achieving 100% on eight simple classification examples does not guarantee 100% accuracy on a much larger real-world dataset.
Common Prompt Engineering Mistakes
While writing prompts, beginners often make a few mistakes that affect the quality of AI-generated responses.
1. Giving vague instructions
A prompt such as “Explain this topic” does not define the audience, expected depth, or format. Adding those details makes the request more useful.
2. Providing insufficient context
The model may not have the information needed to complete a task accurately. Include relevant background information and clearly identify the input.
3. Ignoring output requirements
If an application needs JSON, asking for a general explanation can create unnecessary formatting problems. Specify the required structure.
4. Trusting every response
AI-generated information can contain mistakes. Important calculations, facts, and extracted values should be checked.
5. Testing only one example
A prompt that works for one input may fail on another. Test different cases, including missing information and unusual inputs.
Best Practices for Writing Better Prompts
Here are some practical habits to follow when designing prompts:
- Start with a clear description of the task.
- Provide relevant context and examples when necessary.
- Define the expected output format.
- Use simple and specific language.
- Set constraints for missing or uncertain information.
- Test prompts using multiple representative inputs.
- Compare actual outputs against expected results.
- Refine prompts when errors or inconsistencies appear.
For more detailed guidance, refer to the official Google Gemini prompt design strategies, the OpenAI prompt engineering guide, and Google Cloud’s prompt engineering overview.
Conclusion
Prompt Engineering is an important skill for anyone working with Generative AI and Large Language Models. It helps developers and users communicate their requirements clearly, guide model behaviour, and create more predictable AI-powered workflows.
Through these experiments using Google Gemini, I explored zero-shot and few-shot classification, step-by-step mathematical prompting, and structured JSON extraction. The results demonstrated how different prompt instructions influence the format and usefulness of model responses.
However, effective prompt engineering is not simply about writing longer instructions. It is about understanding the task, providing the right context, setting clear expectations, and evaluating the generated output.
As Generative AI continues to develop, the ability to design, test, and improve prompts will remain valuable for building practical AI applications.
Prompt Engineering is not just about asking AI questions. It is about communicating with AI effectively to achieve meaningful results.



Leave a Reply
You must be logged in to post a comment.