Anatomy of a Prompt
This lesson preview is part of the The Basics of Prompt Engineering course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The Basics of Prompt Engineering, plus 80+ \newline books, guides and courses with the \newline Pro subscription.

[00:00 - 00:10] So now we're going to look at the anatomy of a prompt. Before I go to this section, I just want to say that I'm going to give you a list of elements that a thorough prompt would have.
[00:11 - 00:19] This is not meant to be didactic, right? If you look at the anatomy of a prompt, you are probably going to find a lot of different lists.
[00:20 - 00:25] Some of them are going to have three elements, some are going to have five elements, some are going to have ten. They're all going to overlap.
[00:26 - 00:35] So this isn't a bible for prompting, this is just one framework of many. One that I like to use because I think it's the simplest to understand in terms of crafting a good prompt.
[00:36 - 01:03] You'll see that even within this context, it's not super arbitrary, which is going to be some overlap between these different components of a prompt I'm going to go through. So the components themselves are the task, the detail of the task, the role, which for me only really applies to traditional models, but we'll get to that tone, format, example, and context.
[01:04 - 01:18] Now, task, as you might imagine, is the most basic thing that pretty much absolutely every prompt needs, even a very simple one. Now, it is possible to write a prompt without a task.
[01:19 - 01:25] You can just prompt an alarm by saying hello or something, right? But in the task, you're generally asking it to do something.
[01:26 - 01:35] So you're asking it to do an action that contains a verb, usually. So summarize, spell, calculate, whatever.
[01:36 - 01:45] So for example, you could be asking, summarize the findings of a court case, XY Z. Or you could ask something like write a poem by the bluebirds.
[01:46 - 01:51] Note that there's a verb at the start of those sentences. There's a verb and there's usually a noun, right?
[01:52 - 02:09] And 99% of prompts are going to need at least the task. Now, for very simple prompts, you might be OK with just the task, but usually just a one-line verb, this noun command is going to be imprecise.
[02:10 - 02:18] So that's why we want to give a little bit more detail. Sentence one, the verb the noun, sentence two, give some additional color.
[02:19 - 02:32] So I'm going to use the same two examples throughout, summarizing a legal case and a poem. Here, for example, we could give the detail of, hey, we want you to list the legal statute to which this really implies and how they're affected.
[02:33 - 02:48] Or in the use case of the poem, we could say, hey, we want you to use metaphor extensively, likening the bird to a flower, for example. So this is just getting a little bit more precision and getting a little bit more specificity about what you want.
[02:49 - 02:57] Now, task and detail together are probably going to cover most of your basic use cases. I remember what I said about not over prompting.
[02:58 - 03:18] I think if you're trying to one-shot a prompt, you can start with just the task and the detail, and that will cover a lot of use cases, and if that doesn't work, then you can try to get a little bit more technical with it and start using some of these other components. Now, a role, which I think I already mentioned, is less important than reasoning models.
[03:19 - 03:34] This is because reasoning models are much more task oriented. So when I say role, this is, and you might have seen this on some problems, right, before you have the list of actions you wanted to carry out, you write like a, you are an X or whatever, right?
[03:35 - 03:59] So you could say, if I was generating test data, I would say something like, you're a senior QA developer who has experienced predicting edge cases and building test data for it, right? So to use the two examples I've used already, you could say you're an experienced constitutional lawyer with known for your rigorous attention to detail, or you're a bird watcher and a poet that loves striking imagery.
[04:00 - 04:09] Now, the bit, for example, with striking imagery, that could also have just gone into detail, right? It doesn't necessarily need to go into the role.
[04:10 - 04:30] I'm just pointing that out to show that there is overlap between these concepts and to reiterate that this isn't a super didactic arbitrary list. But role can help. I think the concerningly help in terms of the sources that a model is drawing from, to give your answer and to predict X that comes next.
[04:31 - 04:42] So I'm just, I'm going to show you one of those two example prompts as we go along, just building it up. You can see I've put hash, role hash, task detail.
[04:43 - 04:57] I don't actually usually put these in when I'm writing a prompt for a traditional model, but I'm putting it here just so you guys have the kind of visual feedback. And you can see I've put task and detail together because for me, they're inext ricably linked.
[04:58 - 05:08] Now, tone and tone again is something that really synergizes with role. A lot of people wonder first playing around with chat GPT launch, one of their models launch.
[05:09 - 05:38] They played around with tone a lot, right? You might have seen things like, I don't know, answer this like a pirate or answer this in an Australian accent or something. But aside from just being a fun thing to play around with, it can give a lot more specificity and consistency to your results, especially if you're asking it to, for example, use a professional tone or for the poetry example using a kind of a lively or a lighthearted tone for a fun read.
[05:39 - 05:47] Stuff like this will get you more consistent results. Again, it is linked to role and to complex that we're going to see later.
[05:48 - 06:08] But it's good to know that you can set that tone. Now, next is format, which for more technical tasks is actually probably one of the more important elements, especially if you're generating an output that's then going to be consumed by another system.
[06:09 - 06:17] Or doing something that's going to be read by someone. If you're generating a report or a summary, I think specifying a format is very important.
[06:18 - 06:28] Here I mentioned, in short a summary, follows this report structure, abstract key findings, list of statutes, conclusions, predictions, pretty impact and ruling. Disclaimer, I'm not a lawyer, I've never worked in law.
[06:29 - 06:34] This is probably not a good format for a legal report. I followed my heart.
[06:35 - 06:45] Now, to take the poetry example again, obviously poetry is all about laying, wait, form and format. Here I'm specifying line counts.
[06:46 - 06:56] I'm specifying that I am the contaminator can be used. This is also format is also super important if you're trying to generate, for example, test data.
[06:57 - 07:04] Or if you're doing something that involves code, usually this is important as well. I'll just show you the prompt again as it's being built.
[07:05 - 07:11] You can see we have a role, you're a bird watcher and a poet. Write a poem about bluebirds, metaphor, bird as a flower.
[07:12 - 07:16] Boom, should we let her in fun? Wait, no more than 10 lines in the lesson plan.
[07:17 - 07:30] You can see the prompt taking shape. So alongside format, if you have an output that needs to be really consistent, giving examples can really help.
[07:31 - 07:50] Now, again, this is a synergy between example and format, but you absolutely can get LMS to produce, I put in, say, JSON or CSV format. And if I'm doing that, I like to give an example of the, for example, the JSON structure or the XML structure, whatever you can specify most of these types.
[07:51 - 08:04] And it'll be fairly accurate a lot of the time. But what helps it be a lot more accurate and helps avoid hallucinations is giving a clear example of what a format should look like, what the output should look like.
[08:05 - 08:14] If you're using LML to write code, here I would give an example of, hey, this is the input variables that the function takes. This is what it should add.
[08:15 - 08:42] Bonus points, if you give some negative examples as well, not show the error handling, not just the happy path, I found that tends to get better results. So to look at the two examples we were looking at before, if you're doing a summarization or like a specific report structure, you could include the text of another report that is good and that follows that structure.
[08:43 - 08:56] If you're writing, forgetting an LML to write poetry, you could add excerpts of a poem that you like or that's in a similar style. I use the wild swans at Cool here by WV8, just as an example.
[08:57 - 09:04] I studied in secondary school. Yates, as you can imagine, it's pretty big over here in Ireland and it has birds in it.
[09:05 - 09:12] So it was the first one that jumped to mind. So next we have context.
[09:13 - 09:29] Context, again, like I mentioned, really synergizes with tone and role. So this is something like specifying the audience for your output is probably one of the easiest and most important examples of context, right?
[09:30 - 09:46] So let's say you're writing your legal report. You can specify that this document is going to be read by someone that's senior in the company and it's going to be used to shape strategy around something, right?
[09:47 - 10:07] So that context, I'm going to have this overlap sort of tone, but that context will tell you to use professional language, for example, it'll push the model to use more accurate legal terminology, for example. And then it might help keep the summary that's being generated actionable, right?
[10:08 - 10:18] If you say that this is going into the meeting, there's an implication that this needs to be something actionable. In the case of the poem, something much simpler, this poem is for my eight-year -old daughter.
[10:19 - 10:32] That doesn't really inform anything but the tone, which we've already covered, but it will reinforce that. Whatever kind of output you're generating, if you specify your audience, you will generally get better results.
[10:33 - 10:48] Say if you want to generate a technical blog, specifying, hey, my audience is Q A engineers with one or two years of experience, right? That would help the terminology stay consistent and accurate.
[10:49 - 10:57] So this is the prompt and full. So this has all of the elements we talked about. We have our role, we have our task and our detail, we write a poem about bluebirds.
[10:58 - 11:10] We have the tone and the context kind of put together, because in this case, the tone and the context are the same. The poem should be light-hearted and fun to read because it's for my eight-year -old daughter.
[11:11 - 11:15] So in this case, it's made sense to group them together. Again, you don't have to group these things together.
[11:16 - 11:26] You don't have to specify sections. This is more just for visual fidelity. You can see I'm specifying the format and I'm giving an example.
[11:27 - 11:43] [ Pause ]