{
  "source_file": "0930",
  "source_platform": "个人博客",
  "author": "Eugene Yan",
  "title_listed": "Prompting Fundamentals and How to Apply them Effectively",
  "keywords": "Prompt,提示工程,技巧",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://eugeneyan.com/writing/prompting/",
  "publish_date": "2024-04",
  "corpus_stage": "预训练/SFT",
  "notes": "提示工程基础与实战",
  "id": "fefd32243009",
  "collected_at": "2026-10-02T14:16:46",
  "title": "Prompting Fundamentals and How to Apply them Effectively",
  "body_markdown": "eugeneyan\nStart Here\nWriting\nSpeaking\nPrototyping\nAbout\nPrompting Fundamentals and How to Apply them Effectively\n[\nllm\nproduction\n🔥\n]\n· 17 min read\nWriting good prompts is the most straightforward way to get value out of large language models (LLMs). However, it’s important to understand the fundamentals even as we apply advanced techniques and prompt optimization tools. For example, there’s more to Chain-of-Thought (CoT) than simply adding “think step by step”. Here, we’ll discuss some prompting fundamentals to help you get the most out of LLMs.\nAside: We should know by now that, before doing any major prompt engineering, we need reliable evals. Without evals, how would we measure improvements or regressions? Here’s my usual workflow: (i) manually label ~100 eval examples, (ii) write initial prompt, (iii) run eval, and iterate on prompt and evals, (iv) eval on held-out test set before deployment. Here are write-ups on\npractical evals for key tasks\nand\nhow to build evals with a case study\n.\nWe’ll use the\nClaude Messages API\nfor the prompt and code examples below. The prompts are deliberately kept simple and can be further optimized. The API provides specific roles for the user and assistant, as well as a system prompt.\nimport\nanthropic\nmessage\n=\nanthropic\n.\nAnthropic\n().\nbeta\n.\nmessages\n.\ncreate\n(\nmodel\n=\n\"claude-3-sonnet-20240229\"\n,\nmax_tokens\n=\n1024\n,\nsystem\n=\n\"Today is 26th May 2024.\"\n,\nmessages\n=\n[\n{\n\"role\"\n:\n\"user\"\n,\n\"content\"\n:\n\"Hello there.\"\n},\n{\n\"role\"\n:\n\"assistant\"\n,\n\"content\"\n:\n\"Hi, I'm Claude. How can I help?\"\n},\n{\n\"role\"\n:\n\"user\"\n,\n\"content\"\n:\n\"What is prompt engineering?\"\n},\n]\n)\nMental model: Prompts as conditioning\nAt the risk of oversimplifying, LLMs are essentially sophisticated probabilistic models. Given an input, they generate probable outputs based on patterns learned from data.\nThus, at its core, prompt engineering is about\nconditioning the probabilistic model\nto generate our desired output. Thus, each additional instruction or piece of context can be viewed as conditioning that steers the model’s generation in a particular direction. This mental model applies to\nimage generation\ntoo.\nConsider the prompts below. The first will likely generate a response about Apple the tech company. The second will describe the fruit. And the third will explain the idiom.\n# Prompt 1\nTell me about: Apple\n\n# Prompt 2\nTell me about: Apple fruit\n\n# Prompt 3\nTell me about: Apple of my eye\nBy simply adding a few tokens, we have conditioned the model to respond differently. By extension, prompt engineering techniques like n-shot prompting, structured input and output, CoT, etc. are simply more sophisticated ways of conditioning the LLM.\nAssign roles and responsibilities\nOne way to condition the model’s output is to assign it a specific role or responsibility. This provides it with context that steers its responses in terms of content, tone, style, etc.\nConsider the prompts below: Because the assigned roles vary, we can expect very different responses. The preschool teacher will likely respond with simple language and analogies while the NLP professor may dive into the technical details of attention mechanisms.\n# Prompt 1\nYou are a preschool teacher. Explain how attention in LLMs works.\n\n# Prompt 2\nYou are an NLP professor. Explain how attention in LLMs works.\nRoles and responsibilities can also improve accuracy on most tasks. Imagine we’re building a system to exclude NSFW image generation prompts. While a basic prompt like prompt 1 might work, we can improve the model’s accuracy by providing it with a role (prompt 2) or responsibility (prompt 3). The additional context in prompts 2 and 3 encourages the LLM to scrutinize the input more carefully, thus increasing recall on more subtle issues.\n# Prompt 1\nIs this image generation prompt safe?\n\n# Prompt 2\nClaude, you are an expert content moderator who identifies harmful aspects in prompts.\nIs this image generation prompt safe?\n\n# Prompt 3\nClaude, you are responsible for identifying harmful aspects in prompts.\nIs this image generation prompt safe?\nStructured input and output\nStructured input helps the LLM better understand the task and input, improving the quality of output. Structured output makes it easier to parse responses, simplifying integration with downstream systems. For Claude, XML tags work particularly well while other LLMs may prefer Markdown, JSON, etc.\nIn this example, we ask Claude to extract attributes from a product\n<description>\n.\n<description>\nThe SmartHome Mini is a compact smart home assistant available in black or white for \nonly $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other \nconnected devices via voice or app—no matter where you place it in your home. This \naffordable little hub brings convenient hands-free control to your smart devices.\n</description>\nExtract the\n<name>\n,\n<size>\n,\n<price>\n, and\n<color>\nfrom this product\n<description>\n.\nClaude can reliably follow these explicit instructions and almost always generates output in the requested format.\n<name>\nSmartHome Mini\n</name>\n<size>\n5 inches wide\n</size>\n<price>\n$49.99\n</price>\n<color>\nblack or white\n</color>\nWe can scale this to process multiple documents at once. Here’s an example where we provide product reviews as an array of dicts which we then convert to XML input. (While the example only shows three documents, we can increase the input to dozens, if not hundreds of documents).\nfrom\ndicttoxml\nimport\ndicttoxml\nfrom\nxml.dom.minidom\nimport\nparseString\ndef\ncustom_item_func\n(\nitem\n):\nreturn\n'review'\ndocs\n=\n{\n\"reviews\"\n:\n[\n{\n\"id\"\n:\n1\n,\n\"text\"\n:\n\"The SmartHome Mini is a compact, powerful, and user-friendly smart \n                     home hub. It offers great value for its price.\"\n},\n{\n\"id\"\n:\n2\n,\n\"text\"\n:\n\"The SmartHome Mini is a decent entry-level smart home hub, but it \n                     has some connectivity issues and the app needs improvement.\"\n},\n{\n\"id\"\n:\n3\n,\n\"text\"\n:\n\"Despite being affordable and compact, the SmartHome Mini's \n                     performance is disappointing, with poor voice command \n                     interpretation and unreliable device connections.\"\n}\n]\n}\n# Convert the dictionary to XML\nxml_output\n=\ndicttoxml\n(\ndocs\n,\nattr_type\n=\nFalse\n,\nroot\n=\nFalse\n,\nitem_func\n=\ncustom_item_func\n)\n# Parse the XML string\ndom\n=\nparseString\n(\nxml_output\n)\n# Pretty-print the XML with indentation and spaces\npretty_xml\n=\ndom\n.\ntoprettyxml\n(\nindent\n=\n\"  \"\n)\n# Print the pretty-printed XML\nprint\n(\npretty_xml\n)\nThis gives us the following\n<reviews>\nXML.\n<reviews>\n<review>\n<id>\n1\n</id>\n<text>\nThe SmartHome Mini is a compact, powerful, and user-friendly smart home hub. It \n      offers great value for its price.\n</text>\n</review>\n<review>\n<id>\n2\n</id>\n<text>\nThe SmartHome Mini is a decent entry-level smart home hub, but it has some \n      connectivity issues and the app needs improvement.\n</text>\n</review>\n<review>\n<id>\n3\n</id>\n<text>\nDespite being affordable and compact, the SmartHome Mini's performance is \n      disappointing, with poor voice command interpretation and unreliable \n      device connections.\n</text>\n</review>\n</reviews>\nWe can then prompt Claude to provide a\n<summary>\nof the\n<reviews>\n, with references to the relevant\n<id>\ntags, which  gives us the following output.\n<summary>\nThe SmartHome Mini receives mixed reviews.\n<id>\n1\n</id>\npraises its compact size, power, \nuser-friendliness, and value for money. However,\n<id>\n2\n</id>\nnotes connectivity issues \nand room for app improvement, while\n<id>\n3\n</id>\nfinds the performance disappointing \ndue to poor voice command interpretation and unreliable device connections.\n</summary>\nWe can also prompt it to extract the\n<aspect>\n,\n<sentiment>\n, and corresponding review\n<id>\n, leading to the following:\n<aspect>\ncompact size\n</aspect>\n<sentiment>\npositive\n</sentiment>\n<id>\n1\n</id>\n<aspect>\npower\n</aspect>\n<sentiment>\npositive\n</sentiment>\n<id>\n1\n</id>\n<aspect>\nconnectivity\n</aspect>\n<sentiment>\nnegative\n</sentiment>\n<id>\n2\n</id>\n<aspect>\napp\n</aspect>\n<sentiment>\nnegative\n</sentiment>\n<id>\n2\n</id>\n<aspect>\naffordability\n</aspect>\n<sentiment>\npositive\n</sentiment>\n<id>\n3\n</id>\n<aspect>\nperformance\n</aspect>\n<sentiment>\nnegative\n</sentiment>\n<id>\n3\n</id>\nOverall, while XML tags make take a bit to get used to, it allows us to provide explicit instructions and fine-grained control over structured input and output.\nPrefill Claude’s responses\nPrefilling an LLM’s response is akin to “putting words in its mouth”. For Claude, this guarantees that the generated text will start with the provided tokens (at least in my experience across millions of requests).\nHere’s how we would do this via Claude’s Messages API, where we prefill the assistant’s response with\n<attributes><name>\n. This ensures that Claude will start with these exact tokens, and also make it easier to parse the\n<attributes>\ndownstream.\ninput\n=\n\"\"\"\n<description>\nThe SmartHome Mini is a compact smart home assistant available in black or white for \nonly $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other \nconnected devices via voice or app—no matter where you place it in your home. This \naffordable little hub brings convenient hands-free control to your smart devices.\n</description>\n\nExtract the <name>, <size>, <price>, and <color> from this product <description>.\n\nReturn the extracted attributes within <attributes>.\n\"\"\"\nmessages\n=\n[\n{\n\"role\"\n:\n\"user\"\n,\n\"content\"\n:\ninput\n,\n},\n{\n\"role\"\n:\n\"assistant\"\n,\n\"content\"\n:\n\"<attributes><name>\"\n# Prefilled response\n}\n]\nn-shot prompting\nPerhaps the single most effective technique for conditioning an LLM’s response is n-shot prompting.\nThe idea is to provide the LLM with\nn\nexamples that demonstrate the task and desired output. This steers the model towards the distribution of the n-shot examples and usually leads to improvements in output quality and consistency.\nBut n-shot prompting is a double-edged sword. If we provide too few examples, say three to five, we risk “overfitting” the model (via\nin-context learning\n) to those examples. As a result, if the input differs from the narrow set of examples, output quality could degrade.\nI typically have at least a dozen samples or more. Most academic evals use 32-shot or 64-shot prompts. (This is also why I tend not to call this technique few-shot prompting because “few” can be misleading on what it takes to get reliable performance.)\nWe also want to ensure that our n-shots are representative of expected production inputs. If we’re building a system to extract aspects and sentiments from product reviews, we’ll want to include examples from multiple categories such as electronics, fashion, groceries, media, etc. Also, take care to match the distribution of examples to production data. If 80% of production aspects are positive, the n-shot prompt should reflect that too.\ninput\n=\n\"\"\"\n<description>\nThe SmartHome Mini is a compact smart home assistant available in black or white for \nonly $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other \nconnected devices via voice or app—no matter where you place it in your home. This \naffordable little hub brings convenient hands-free control to your smart devices.\n</description>\n\nExtract the <name>, <size>, <price>, and <color> from this product <description>.\n\nHere are some <examples> of <description> and extracted <attributes>:\n<examples>\n<description>\nIntroducing the sleek and powerful UltraBook Pro laptop ... (truncated)\n</description>\n<attributes>\n<name>UltraBook Pro</name>  \n<color>silver, space gray</color>\n<size>14\" display, 2.8lbs</size>\n<price>$1,299</price>\n</attributes>\n\n  \n<description>\nSpark imagination and creativity with the Mega Blocks Construction Set ... (truncated)\n</description>\n<attributes>\n<name>Mega Blocks Construction Set</name>\n<color>colorful</color>  \n<size>200 pieces</size>\n<price>$24.99</price>\n</attributes>\n\n<description>\nThe perfect little black dress for any occasion ... (truncated)\n</description>  \n<attributes>\n<name>Little Black Sheath Dress</name>\n<color>black</color>\n<size>petite, regular, tall lengths, sizes 2-16</size>\n<price>$89.99</price>  \n</attributes>\n\n<description>\nStay hydrated on the trail with the HydroFlow Water Bottle ... (truncated)\n</description>\n<attributes>  \n<name>HydroFlow Water Bottle</name>\n<color>6 colors</color>\n<size>24 oz</size>\n<price>$21.99</price>  \n</attributes>\n\n<description>\nAchieve a flawless complexion with Glow Perfect Foundation ... (truncated)\n</description>\n<attributes>\n<name>Glow Perfect Foundation</name>\n<color>20 shades</color>\n<size>1 fl oz</size>\n<price>$32</price>\n</attributes>\n\n(... examples truncated)\n\n</examples>\n\nReturn the <name>, <size>, <price>, and <color> within <attributes>.\n\"\"\"\nmessages\n=\n[\n{\n\"role\"\n:\n\"user\"\n,\n\"content\"\n:\ninput\n,\n},\n{\n\"role\"\n:\n\"assistant\"\n,\n\"content\"\n:\n\"<attributes><name>\"\n# Prefilled response\n}\n]\nThat said, the number of examples needed will vary based on the complexity of the task. For simpler goals such as enforcing output format/structure or response tone, as few as five examples may suffice. In such instances, we may only need to provide the desired output as examples rather than the usual input-output pairs.\nDiving deeper into Chain-of-Thought\nThe basic idea of CoT is to give the LLM “space to think” before generating its final output. The intermediate reasoning allows the model to break down the problem and condition its own response, often leading to better results, especially if the task is complex.\nThe standard approach is to simply add the phrase “think step by step”.\nClaude, you are responsible for accurately summarizing the meeting <transcript>.\n\n<transcript>\n{transcript}\n</transcript>\n\nThink step by step and return a <summary> of the <transcript>.\nHowever, we can do more to improve the effectiveness of CoT.\nOne idea is to contain the CoT within a designated\n<sketchpad>\n, and then generate the\n<summary>\nbased on the sketchpad. This makes it easier to parse the final output and exclude the CoT if needed. To ensure we start with the sketchpad, we can\nprefill\nClaude’s response with the opening\n<sketchpad>\ntag.\nClaude, you are responsible for accurately summarizing the meeting <transcript>.\n\n<transcript>\n{transcript}\n</transcript>\n\nThink step by step on how to summarize the <transcript> within the provided <sketchpad>.\n\nThen, return a <summary> based on the <sketchpad>.\nAnother way to improve CoT is to provide more specific instructions for the reasoning process. For example:\nClaude, you are responsible for accurately summarizing the meeting <transcript>.\n\n<transcript>\n{transcript}\n</transcript>\n\nThink step by step on how to summarize the <transcript> within the provided <sketchpad>.\n\nIn the <sketchpad>, return a list of <decision>, <action_item>, and <owner>.\n\nThen, check that <sketchpad> items are factually consistent with the <transcript>.\n\nFinally, return a <summary> based on the <sketchpad>.\nBy guiding the model to look for specific information and verify its intermediate outputs against the source document, we can significantly improve factual consistency (i.e., reduce hallucination). In some cases, we’ve observed that adding a sentence or two to the CoT prompt removed the majority of hallucinations.\nSplit catch-all prompts into multiple smaller ones\nWe can sometimes improve performance by refactoring a large, catch-all prompt into several, single-purpose prompts (akin to having small, single responsibility functions). This helps the model focus on only one task at each step, increasing performance at each step and thus, final output quality. While this will increase total input token count, the overall cost need not be higher if we use smaller models for some simpler steps.\nHere’s how we might split our meeting transcript summarizer above into multiple prompts. First, we’ll use Haiku to extract the decisions, action items, and owners.\n# Prompt to extract transcript attributes via Haiku\nClaude, you are responsible for accurately extracting information from the <transcript>.\n\n<transcript>\n{transcript}\n</transcript>\n\nFrom <transcript>, extract a list of <decision>, <action_item>, and <owner>.\n\nReturn the list within <extracted_information>.\nThen, we can verify that the extracted items are consistent with the transcript via Sonnet.\n# Prompt to verify extracted attributes via Sonnet\nClaude, you are responsible for checking <extracted_information> against a <transcript>.\n\nHere is the meeting transcript:\n<transcript>\n{transcript}\n</transcript>\n\nHere is the extracted information:\n<extracted_information>\n{extracted_information}\n</extracted_information>\n\nThink step by step and check that the <extracted_information> is factually consistent \nwith the <transcript> within the <sketchpad>.\n\nThen, return a list of factually consistent <decision>, <action_item>, and <owner>\nwithin <confirmed_extracted_information>.\nFinally, we can use Haiku to format the extracted information.\n# Prompt to rewrite transcript attributes into bulletpoints via Haiku\nClaude, you are responsible for converting <information> into bullet-point summaries.\n\n<information>\n{confirmed_extracted_information}\n</information>\n\nRewrite the <information> into bullets for either <decision> or <action item>, with \nthe <owner> in parentheses.\nAs an example,\nAlphaCodium\nshared that by switching from a single direct prompt to a multi-step workflow, they increased gpt-4 accuracy (pass@5) on CodeContests from 19% to 44%. Their coding workflow had multiple steps/prompts including:\nReflecting on the problem\nReasoning on the public tests\nGenerating possible solutions\nRanking possible solutions\nGenerating synthetic tests\nIterating on the solution with public and synthetic tests\nOptimal placement context\nI’m often asked where to put the document or context within the prompt. For Claude, I’ve found that putting the context near the beginning tends to work best, with a structure like:\nRole or responsibility (usually brief)\nContext/document\nSpecific instructions\nPrefilled response\nThis aligns with the role-context-task pattern used in many of Anthropic’s own examples.\nNonetheless, the optimal placement may vary across different models depending on how they were trained. If you have reliable evals, it’s worth experimenting with different context locations and measuring the impact on performance.\nCrafting effective instructions\nShort, focused sentences separated by new lines tends to work best. I haven’t found other formats like paragraphs, bullet points, or numbered lists to work as well. Nonetheless, the meta on writing instructions is constantly evolving so it’s good to keep an eye on the latest system prompts. Here’s\nClaude 3’s system prompt\n; and here’s\nChatGPT’s\n.\nAlso, it’s natural to add more and more instructions to our prompts to better handle edge cases and eke out more performance. But just like software, prompts can get bloated over time. Before we know it, our once-simple prompt has grown into a hundred lines. To add injury to insult, the Frankenstein-ed prompt actually performs worse on more common and straightforward inputs! Thus, periodically refactor prompts—just like software—and prune instructions that are no longer needed.\nDealing with hallucinations\nThis is a tricky one. While some techniques help with hallucinations, none are foolproof. Thus, do not assume that applying these will completely eliminate hallucinations.\nFor tasks involving extraction or question answering, include an instruction that allows the LLM to say “I don’t know” or “Not applicable”. Additionally, try instructing the model to only provide an answer if it’s highly confident. Here’s an example:\nClaude, answer the following question based on the provided <context>.\n\n<context>\n{context}\n</context>\n\nIf the question CANNOT be answered based on the <context>, respond with \"I don't know\".\n\nOnly provide an answer if you are highly confident it is factually correct.\n\nQuestion: {question}\n\nAnswer:\nFor tasks that involve more reasoning, CoT can help reduce hallucinations. By providing a\n<sketchpad>\nfor the model to think and check its intermediate output before providing the final answer, we can improve the factual grounding of the output. The previous example of summarizing meeting transcripts (reproduced below) is a good example.\nClaude, you are responsible for summarizing meeting <transcripts>.\n\n<transcript>\n{transcript}\n</transcript>\n\nThink step by step on how to summarize the <transcript> within the provided <sketchpad>.\n\nIn the <sketchpad>, identify the <key decisions>, <action items>, and their <owners>.\n\nThen, check that the <sketchpad> items are factually consistent with the <transcript>.\n\nFinally, return a <summary> based on the <sketchpad>.\nUsing the stop sequence\nThe stop sequence parameter allows us to specify words or phrases that signal the end of the desired output. This prevents trailing text, reduces latency, and makes the model’s responses easier to parse. When working with Claude, the convenient option is to use the closing XML tag (e.g.,\n</attributes>\n) as the stop sequence.\ninput\n=\n\"\"\"\n<description>\nThe SmartHome Mini is a compact smart home assistant available in black or white for \nonly $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other \nconnected devices via voice or app—no matter where you place it in your home. This \naffordable little hub brings convenient hands-free control to your smart devices.\n</description>\n\nExtract the <name>, <size>, <price>, and <color> from this product <description>.\n\nReturn the extracted attributes within <attributes>.\n\"\"\"\nmessage\n=\nanthropic\n.\nAnthropic\n().\nmessages\n.\ncreate\n(\nmodel\n=\n\"claude-3-opus-20240229\"\n,\nmax_tokens\n=\n1024\n,\nmessages\n=\n[\n{\n\"role\"\n:\n\"user\"\n,\n\"content\"\n:\ninput\n,\n},\n{\n\"role\"\n:\n\"assistant\"\n,\n\"content\"\n:\n\"<attributes><name>\"\n}\n],\nstop_sequences\n=\n[\n\"</attributes>\"\n]\n# Added the stop sequence here\n)\nSelecting a temperature\nThe temperature parameter controls the “creativity” of a model’s output. It ranges from 0.0 to 1.0, with higher values resulting in more diverse and unpredictable responses while lower values produce more focused and deterministic outputs. (Confusingly, OpenAI APIs allow\ntemperature values as high as 2.0\n, but this is not the norm.)\nMy rule of thumb is to start with a temperature of 0.8 and then lower it as necessary. What we want is the highest temperature that still leads to good results for the specific task.\nAnother heuristic is to use lower temperatures (closer to 0) for analytical or multiple-choice tasks, and higher temperatures (closer to 1) for creative or open-ended tasks. Nonetheless, I’ve found that too low a temperature reduces the model’s intelligence (thus my preferred approach of starting from 0.8 and lowering it only if necessary). Also see Kyle Corbitt\nconfirming this for gpt-4\nbut\nnot finetuned llama3-8b\n.\nWhat doesn’t seem to matter\nThere are a few things that, based on my experience and discussions with others, don’t have a practical impact on performance (at least for recent models):\nCourtesy: Adding phrases like “please” and “thank you” doesn’t affect output quality much, even if it might earn us some goodwill with our future AI overlords.\nTips and threats: Recent models are generally good at following instructions without the need to offer a “$200 tip” or threatening that we will “lose our job”.\nOf course, it doesn’t hurt to be polite or playful in our prompts. Nonetheless, it’s useful to know that they’re not as critical for getting good results.\n• • •\nAs LLMs continue to improve, prompt engineering will remain a valuable skill for getting the most out of LLMs (though we may soon transition to\n“dictionary learning”\n). What other prompting techniques have you found useful? Please comment below or\nreach out\n!\nIf you found this useful, please cite this write-up as:\nYan, Ziyou. (May 2024). Prompting Fundamentals and How to Apply them Effectively. eugeneyan.com.\n        https://eugeneyan.com/writing/prompting/.\nor\n@article{yan2024prompting,\n  title   = {Prompting Fundamentals and How to Apply them Effectively},\n  author  = {Yan, Ziyou},\n  journal = {eugeneyan.com},\n  year    = {2024},\n  month   = {May},\n  url     = {https://eugeneyan.com/writing/prompting/}\n}\nShare on:\nBrowse related tags:\n[\nllm\nproduction\n🔥\n]\nor\nSearch\n« What We've Learned From A Year of Building with LLMs\nNetflix PRS 2024 - Applying LLMs to Recommendation Experiences »\nJoin\n11,800+\nreaders getting updates on machine learning, RecSys, LLMs, and engineering.\nGet email updates",
  "metadata": {
    "title": "Prompting Fundamentals and How to Apply them Effectively",
    "description": "Structured input/output, prefilling, n-shots prompting, chain-of-thought, reducing hallucinations, etc.",
    "keywords": null,
    "author": "Eugene Yan",
    "og:site_name": "eugeneyan.com",
    "og:title": "Prompting Fundamentals and How to Apply them Effectively",
    "og:type": "article",
    "og:description": "Structured input/output, prefilling, n-shots prompting, chain-of-thought, reducing hallucinations, etc.",
    "og:url": "https://eugeneyan.com/writing/prompting/",
    "og:image": "https://eugeneyan.com/assets/og_image/prompting.jpg",
    "twitter:card": "summary_large_image",
    "twitter:domain": "eugeneyan.com",
    "twitter:title": "Prompting Fundamentals and How to Apply them Effectively",
    "twitter:description": "Structured input/output, prefilling, n-shots prompting, chain-of-thought, reducing hallucinations, etc.",
    "twitter:image": "https://eugeneyan.com/assets/og_image/prompting.jpg",
    "article:published_time": "2024-05-26T00:00:00+00:00",
    "article:author": "https://eugeneyan.com/about/",
    "article:section": "posts",
    "article:tag": "🔥"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/fefd32243009/code/body-000.txt",
      "chars": 369,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-001.txt",
      "chars": 114,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-002.txt",
      "chars": 152,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-003.txt",
      "chars": 308,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-004.txt",
      "chars": 452,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-005.txt",
      "chars": 109,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-006.txt",
      "chars": 1156,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-007.txt",
      "chars": 653,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-008.txt",
      "chars": 356,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-009.txt",
      "chars": 422,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-010.txt",
      "chars": 702,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-011.txt",
      "chars": 2079,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-012.txt",
      "chars": 186,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-013.txt",
      "chars": 264,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-014.txt",
      "chars": 429,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-015.txt",
      "chars": 309,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-016.txt",
      "chars": 582,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-017.txt",
      "chars": 334,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-018.txt",
      "chars": 300,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-019.txt",
      "chars": 428,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-020.txt",
      "chars": 898,
      "language": "text"
    },
    {
      "file": "attachments/fefd32243009/code/body-021.txt",
      "chars": 249,
      "language": "text"
    }
  ],
  "images": [
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/icon-search.svg",
      "bytes": 425,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-feeb4bd87b8704a903b2.svg",
      "src": "https://eugeneyan.com/assets/icon-search.svg",
      "alt": "",
      "downloaded": true
    },
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/icon-twitter.svg",
      "bytes": 892,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-0083a7581b07e5f40e7b.svg",
      "src": "https://eugeneyan.com/assets/icon-twitter.svg",
      "alt": "",
      "downloaded": true
    },
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/icon-linkedin.svg",
      "bytes": 559,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-f7a16c3e46e5838cec4d.svg",
      "src": "https://eugeneyan.com/assets/icon-linkedin.svg",
      "alt": "",
      "downloaded": true
    },
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/bluesky.svg",
      "bytes": 745,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-be754e8ecdaf6de94f55.svg",
      "src": "https://eugeneyan.com/assets/bluesky.svg",
      "alt": "",
      "downloaded": true
    },
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/icon-facebook.svg",
      "bytes": 1123,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-5d55b59733923cf14223.svg",
      "src": "https://eugeneyan.com/assets/icon-facebook.svg",
      "alt": "",
      "downloaded": true
    },
    {
      "status": "ok",
      "url": "https://eugeneyan.com/assets/icon-mail.svg",
      "bytes": 841,
      "reused": false,
      "local_path": "attachments/fefd32243009/images/body-b179147617228dfafb9f.svg",
      "src": "https://eugeneyan.com/assets/icon-mail.svg",
      "alt": "",
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://eugeneyan.com/",
      "label": "eugeneyan",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/start-here/",
      "label": "Start Here",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/writing/",
      "label": "Writing",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/speaking/",
      "label": "Speaking",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/prototyping/",
      "label": "Prototyping",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/about/",
      "label": "About",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/search/",
      "label": "",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/tag/llm/",
      "label": "llm",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/tag/production/",
      "label": "production",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/tag/🔥/",
      "label": "🔥",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/writing/evals/",
      "label": "practical evals for key tasks",
      "type": "a"
    },
    {
      "href": "https://hamel.dev/blog/posts/evals/",
      "label": "how to build evals with a case study",
      "type": "a"
    },
    {
      "href": "https://docs.anthropic.com/en/api/messages-examples",
      "label": "Claude Messages API",
      "type": "a"
    },
    {
      "href": "https://fullstackdeeplearning.com/llm-bootcamp/spring-2023/prompt-engineering/",
      "label": "conditioning the probabilistic model",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/writing/text-to-image/",
      "label": "image generation",
      "type": "a"
    },
    {
      "href": "https://arxiv.org/abs/2005.14165",
      "label": "in-context learning",
      "type": "a"
    },
    {
      "href": "https://arxiv.org/abs/2401.08500",
      "label": "AlphaCodium",
      "type": "a"
    },
    {
      "href": "https://x.com/AmandaAskell/status/1765207842993434880",
      "label": "Claude 3’s system prompt",
      "type": "a"
    },
    {
      "href": "https://x.com/krishnanrohit/status/1755123169353236848",
      "label": "ChatGPT’s",
      "type": "a"
    },
    {
      "href": "https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter",
      "label": "temperature values as high as 2.0",
      "type": "a"
    },
    {
      "href": "https://x.com/corbtt/status/1801026166020833457",
      "label": "confirming this for gpt-4",
      "type": "a"
    },
    {
      "href": "https://x.com/corbtt/status/1801059164954775643",
      "label": "not finetuned llama3-8b",
      "type": "a"
    },
    {
      "href": "https://www.anthropic.com/news/mapping-mind-language-model",
      "label": "“dictionary learning”",
      "type": "a"
    },
    {
      "href": "https://x.com/eugeneyan",
      "label": "reach out",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/writing/llm-lessons/",
      "label": "« What We've Learned From A Year of Building with LLMs",
      "type": "a"
    },
    {
      "href": "https://eugeneyan.com/speaking/netflix-prs/",
      "label": "Netflix PRS 2024 - Applying LLMs to Recommendation Experiences »",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:52:15Z",
  "source_url": "https://eugeneyan.com/writing/prompting/",
  "papers": [
    {
      "status": "ok",
      "url": "https://arxiv.org/pdf/2005.14165",
      "bytes": 6768044,
      "reused": true,
      "local_path": "papers/repair/0c1629d8d07d676c2aae.pdf"
    },
    {
      "status": "ok",
      "url": "https://arxiv.org/pdf/2401.08500",
      "bytes": 475308,
      "reused": true,
      "local_path": "papers/repair/67008eeb943c437e182e.pdf"
    }
  ],
  "actual_video_files": [],
  "body_chars": 24526,
  "expected_body_images": 6,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/fefd32243009/pages/source.html",
  "local_html": "attachments/fefd32243009/pages/article.html",
  "body_base_path": "attachments/fefd32243009/pages/",
  "body_markdown_path": "attachments/fefd32243009/pages/article.md"
}