useful tools, especially for programmers. I literally use LLMs every single day, and can’t imagine a world without them. However, there are a few particular techniques you can utilize to achieve even greater results with LLMs.
I’ve covered a few different techniques in previous articles, such as:
- Using Slash commands
- Utilizing plan mode
- Continuously updating agents.md
In this article, I’ll cover how you can leverage few-shot prompting to have your LLMs perform even better.
Why use few-shot prompting
Firstly, I want to cover why you should utilize few-shot prompting. Few-shot prompting is incredibly useful because it allows you to show the LLM your intent without having to explicitly write the intent out in your prompt.
For example, let’s say you want a website done in…
useful tools, especially for programmers. I literally use LLMs every single day, and can’t imagine a world without them. However, there are a few particular techniques you can utilize to achieve even greater results with LLMs.
I’ve covered a few different techniques in previous articles, such as:
- Using Slash commands
- Utilizing plan mode
- Continuously updating agents.md
In this article, I’ll cover how you can leverage few-shot prompting to have your LLMs perform even better.
Why use few-shot prompting
Firstly, I want to cover why you should utilize few-shot prompting. Few-shot prompting is incredibly useful because it allows you to show the LLM your intent without having to explicitly write the intent out in your prompt.
For example, let’s say you want a website done in a particular way, similar to a previous website you made. And without few-shot prompting, you could try to describe the previous website you want replicated and have the LLM create that new website. However, this will likely lead to a lot of ambiguity in your prompt, where the LLM has to make some assumptions. Thus, you will likely not achieve the result you are looking for.
If instead you provide the LLM with the actual codebase, or at least some screenshots of your previous website, and simply ask it to replicate the website, you will achieve much better results. This essentially removes all ambiguity from your prompt and helps the LLM achieve much greater results.
I’m arguing for the fact that you should use this few-shot prompting technique in everything you do. As long as it’s not the first time you’re working on a task, always refer to some of your previous work for how the LLM should do something. For example:
- Making marketing material? -> show the LLM your previous work
- Adding a new feature to your app? -> show the LLM your previous features
- Creating new slash commands? -> show the LLM how you structured your previous slash commands
I almost guarantee you that by referring to your previous work and showing the LLM how to do something not only in the prompt, but in actual implementation, you’ll achieve much greater results.
This infographic highlights the main contents of this article. I’ll discuss few-shot prompting and how you leverage it to optimize your LLM’s performance. I’ll cover points like: organizing your past work, how to provide few-shot examples, iterating on your work, and how expanding your library of work will further increase your LLM’s performance. Image by Gemini
How to implement few-shot prompting
Now I want to discuss how to implement few-shot prompting. Few-shot prompting is not something you can always implement. Some tasks are simply new, and it’s very hard to take advantage of or leverage previous work that you’ve done because the new work simply isn’t similar enough.
This is completely fine and something you should accept. However, you should always look for opportunities to leverage few-shot prompting. Firstly, I’ll discuss how you should organize your work to increase the surface area for few-shot prompting opportunities, and I’ll then show you how to do few-shot prompting in practice, using examples.
Organizing your work
Firstly, it’s important that you organize all your work in accessible folders on your computer. Personally, I store almost everything I do within a programming main folder. I then have a folder structure of the code repositories I’m typically working in. Another folder consisting of some personal projects I am accessing sometimes. Another folder with the marketing material I’m working on, such as LinkedIn posts and short-form videos, and another folder for all of the presentations I’m holding on AI.
Now, whenever I start a new task, my first job is always to figure out which folder this work belongs to. In general, organizing work like this is just general computer organizing hygiene. However, being organized like this makes it so much simpler to take advantage of few-shot prompting in the future. I just always recommend spending some time figuring out where your work belongs in the beginning so that you can take advantage of it on a later occasion.
Furthermore, you should always be committing your work to GitHub. The reason for this is that it allows you to store all your progress and provides you with a version history. So if something happens to your computer, or you make changes you want to revert, you can easily revert them using Git.
Furthermore, if you don’t have knowledge of using Git, it’s not really an issue, as you can simply use an LLM to interact with Git for you. You don’t really have to interact with Git at all yourself.
Few-shot prompting in action
Now, assuming you’ve organized your work properly, it’s time to start taking advantage of few-shot prompting. The concept of few-shot prompting is pretty simple. Whenever you start new work, you simply refer to a folder or file of previous work that you want the computer to either replicate or follow the same styling or similar.
I think it’s easiest if I show you, if I describe some specific examples of how I use few-shot prompting in practice.
Writing code
Probably the most common use case for me when few-shot prompting is writing code. Let’s say I want to implement a GitHub Actions validation script in a new repository. I essentially never ask Claude Code to come up with this script from scratch. Instead, I simply tell Claude Code, “This script exists in folder X, replicate or duplicate the script exactly in the repository I’m currently working on. However, just make this one change where you don’t run the part of the validation script”.
This has two main benefits. For one, I’m almost certain I’ll get the GitHub Actions validation script I’m expecting, because I know it’s working in the other repository. Furthermore this is great because even though I’m copying over the script from another repository, I’m still able to make changes. And in this example, the change was that I don’t want to run the full validation script. I want to skip one part of it in this new repository.
Claude Code is great at dealing with these kinds of tasks, where you tell it to replicate some other piece of code and then make a few customized changes. Which is why this works so well.
Creating marketing material
Another very common use case I have for few-shot prompting is creating marketing material. Creating fresh marketing material can be a time-consuming task. You have to, for example, create brand new presentations or carousel views to be used on LinkedIn.
Furthermore, it is often hard to describe your exact preferences when it comes to presentations. You might want a particular kind of font style or a particular kind of alignment of text and images in your presentations. This is simply hard to describe in natural language, but it’s very clear to the model if you show it an example of how this text font is or how text and images are aligned from your previous work.
Thus, when I’m making a new presentation nowadays, I always show Claude Code my previous presentations and tell it the things I want to change from those previous presentations. The things I want to change are typically the actual content of the presentation, of course, where I describe each page in my presentation to as much detail as possible. This is, of course, important to keep the content yours and not AI-generated.
Furthermore, I simply iterate a lot with Claude Code. I told it to make me an initial draft of the presentation. I then review the draft, transcribe all of the changes I want changed through MacWhisper while reviewing the presentation, and have the AI make a second draft. I’ll then continue like this until I’m happy with the presentation.
Slash commands
Creating slash commands is also something I do on a pretty regular basis. Slash commands are essentially stored prompts that you can have with the code that allows you to access prompts rapidly. I typically have slash commands for commands like creating a pull request to dev, creating a pull request to main, simplifying code, or running a PR review.
However, I typically want my slash commands to follow a particular kind of structure. The structure is a markdown structure with a few points that I generally share across my different slash commands. Thus, showing Claude Code my previous slash commands makes the generation of new slash commands a lot simpler, faster, and more likely to follow the preferences I have.
Conclusion
In this article, I’ve discussed how to leverage few-shot prompting to achieve the best results with your LLMs. Active usage of few-shot prompting by showing the LLM examples of your previous work can make your LLM far more efficient for your use cases. I recommend always striving to use few-shot prompting whenever you work with LLMs to achieve the best results. The best part of few-shot prompting is that it gets better the more work you do. The more work you do, the more previous examples you have to show the LLM, and the better it will perform according to your preferences, which is what makes it such a great technique.
👉 My free eBook and Webinar:
🚀 10x Your Engineering with LLMs (Free 3-Day Email Course)
📚 Get my free Vision Language Models ebook
💻 My webinar on Vision Language Models
👉 Find me on socials:
💌 Substack