Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST

AWS Basic Prompt Techniques


Basic Prompt Techniques

When crafting and manipulating prompts, you can use specific techniques to achieve the response you want from AI models.

In this lesson, you learn how to use various prompt engineering techniques to help you use generative AI applications effectively for your unique business objectives.


Zero-shot prompting

Zero-shot prompting is a technique where you present a task to an LLM without giving the model further examples.

With zero-shot prompting, you expect the model to perform the task without a prior understanding, or shot, of the task.

Modern LLMs demonstrate remarkable zero-shot performance.

zero shot prompting illustration

Image created by Amazon Web Services.

The following tips can help you use zero-shot prompting:

  • Larger LLMs are more likely to produce effective results with zero-shot prompts.
  • Instruction tuning can improve zero-shot learning. You can use reinforcement learning from human feedback (RLHF) to scale instruction tuning, aligning modern LLMs to better fit human preferences.

Zero-shot prompt example

U
Tell me the sentiment of the following social media post and categorize it as positive, negative, or neutral:

Don't miss the electric vehicle revolution! AnyCompany is ditching muscle cars for EVs, creating a huge opportunity for investors.
AI
Positive

Note: This prompt did not provide any examples to the model. However, the model was still effective in deciphering the task.


Few-shot prompting

Few-shot prompting is a technique where you provide the model with contextual information about requested tasks. You include examples of both the task and the output you want, helping the model follow your guidance closely.

few-shot prompting illustration

Image created by Amazon Web Services.

When using few-shot prompting, consider:

  • Labels in a few-shot prompt don't need to be correct to improve performance. Random labels often perform better than no labels at all. However, the label space and distribution of input text are important.
  • If you have many examples, use techniques to comply with token limits and dynamically populate prompt templates. An example selector based on semantic similarity can help.

Few-shot prompt example

U
Tell me the sentiment of the following headline and categorize it as either positive, negative, or neutral. Here are some examples:

Research firm fends off allegations of impropriety over new technology.
Answer: Negative

Offshore windfarms continue to thrive as vocal minority in opposition dwindles.
Answer: Positive

Manufacturing plant is the latest target in investigation by state officials.
Answer:
AI
Negative

Note: The Amazon Titan Text model was used in this example.


Chain-of-thought prompting

Chain-of-thought (CoT) prompting breaks down complex reasoning tasks through intermediary reasoning steps. You can use both zero-shot and few-shot techniques with CoT prompts.

chain-of-thought prompting illustration

Image created by Amazon Web Services.

CoT prompts are specific to a problem type. Use the phrase "Think step by step" to invoke CoT reasoning.

Tip: Use CoT prompting when the task involves several steps or requires a series of reasoning.

CoT zero-shot prompt example

U
Which vehicle requires a larger down payment based on the following information?

The total cost of vehicle A is $40,000, and it requires a 30 percent down payment.
The total cost of vehicle B is $50,000, and it requires a 20 percent down payment.

(Think step by step)
AI
The down payment for vehicle A is 30 percent of $40,000, which is (30/100) * 40,000 = $12,000.

The down payment for vehicle B is 20 percent of $50,000, which is (20/100) * 50,000 = $10,000.

We can see that vehicle A needs a larger down payment than vehicle B.

Note: This prompt did not provide examples to the model, yet the model was still effective in deciphering the task.

CoT few-shot prompt example

CoT prompting becomes more powerful when combined with few-shot prompting:

U
In a given week, the viewers for a TV channel are as follows:
Monday: 6,500 viewers
Tuesday: 6,400 viewers
Wednesday: 6,300 viewers

Question: How many viewers can we expect on Friday?
Answer: Based on the numbers given and without any more information, there is a daily decrease of 100 viewers. If we assume this trend will continue, we can expect 6,200 viewers on Thursday, and therefore 6,100 viewers on Friday.

Question: How many viewers can we expect on Saturday? (Think step by step)
Answer:

This prompt provides both few-shot context (a question-and-answer example) and CoT prompting ("Think step by step").


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.