[{"data":1,"prerenderedAt":3344},["ShallowReactive",2],{"page-\u002Fprompt-engineering\u002F03-zero-shot-and-few-shot-prompting":3},{"id":4,"title":5,"body":6,"description":3337,"extension":3338,"meta":3339,"navigation":74,"path":3340,"seo":3341,"stem":3342,"__hash__":3343},"content\u002Fprompt-engineering\u002F03-zero-shot-and-few-shot-prompting.md","03 — Zero-Shot & Few-Shot Prompting",{"type":7,"value":8,"toc":3316},"minimark",[9,13,22,27,35,94,101,106,205,215,219,222,226,313,320,324,530,545,549,564,568,651,669,681,685,696,1506,1529,1533,1548,1969,1987,1991,1998,2078,2088,2092,2095,2166,2172,2177,2255,2258,2262,2265,2382,2385,2423,2427,2632,2684,2759,2808,2812,2858,2904,2969,3005,3051,3055,3058,3120,3123,3166,3170,3312],[10,11,5],"h1",{"id":12},"_03-zero-shot-few-shot-prompting",[14,15,16,17,21],"p",{},"No hand-holding. Zero-shot = instructions only, model infers the task from pretraining. Few-shot = demonstrate the task with input\u002Foutput pairs, model in-fills the pattern. The engineering question is never \"which is better\" — it's \"what does ",[18,19,20],"em",{},"this"," task require, and what will it cost at scale.\" This chapter shows both, the failure modes that kill production prompts, and the selection\u002Fordering strategy that separates a working few-shot set from a silent misclassifier.",[23,24,26],"h2",{"id":25},"zero-shot-classification-with-exact-output-contract","Zero-Shot Classification with Exact Output Contract",[14,28,29,30,34],{},"Zero-shot works when the task is common enough that the model has generalized it from pretraining. The only engineering discipline required: an ",[31,32,33],"strong",{},"exact output contract"," — the set of valid labels, the format, and the constraint that nothing else is emitted.",[36,37,39],"code-wrapper",{"language":38},"markdown",[40,41,45],"pre",{"className":42,"code":43,"language":38,"meta":44,"style":44},"language-markdown shiki shiki-themes github-light github-dark","Classify the sentiment of this product review.\nValid labels: POSITIVE | NEGATIVE | MIXED\nRespond with exactly one label. No explanation, no punctuation, no prose.\n\nReview: \"The build quality is fantastic and it feels premium, but the\nbattery life is genuinely disappointing for the price point.\"\nLabel:\n","",[46,47,48,57,63,69,76,82,88],"code",{"__ignoreMap":44},[49,50,53],"span",{"class":51,"line":52},"line",1,[49,54,56],{"class":55},"ssxIu","Classify the sentiment of this product review.\n",[49,58,60],{"class":51,"line":59},2,[49,61,62],{"class":55},"Valid labels: POSITIVE | NEGATIVE | MIXED\n",[49,64,66],{"class":51,"line":65},3,[49,67,68],{"class":55},"Respond with exactly one label. No explanation, no punctuation, no prose.\n",[49,70,72],{"class":51,"line":71},4,[49,73,75],{"emptyLinePlaceholder":74},true,"\n",[49,77,79],{"class":51,"line":78},5,[49,80,81],{"class":55},"Review: \"The build quality is fantastic and it feels premium, but the\n",[49,83,85],{"class":51,"line":84},6,[49,86,87],{"class":55},"battery life is genuinely disappointing for the price point.\"\n",[49,89,91],{"class":51,"line":90},7,[49,92,93],{"class":55},"Label:\n",[14,95,96,97,100],{},"The contract has three parts: (1) a closed enum of labels, (2) \"exactly one,\" (3) \"no explanation.\" Without all three, the model may emit \"MIXED — because…\" and downstream regex\u002FJSON parsing breaks. The instruction ",[18,98,99],{},"is"," the prompt — zero example tokens spent.",[102,103,105],"h3",{"id":104},"production-wrapper-system-message-structured-output","Production wrapper: system message + structured output",[36,107,109],{"language":108},"json",[40,110,113],{"className":111,"code":112,"language":108,"meta":44,"style":44},"language-json shiki shiki-themes github-light github-dark","{\n  \"model\": \"claude-opus-5\",\n  \"max_tokens\": 10,\n  \"system\": \"You are a sentiment classifier. Valid labels: POSITIVE, NEGATIVE, MIXED. Respond with exactly one label. No other text.\",\n  \"messages\": [\n    {\"role\": \"user\", \"content\": \"The build quality is fantastic but battery life is disappointing.\"}\n  ]\n}\n",[46,114,115,120,136,148,160,168,195,200],{"__ignoreMap":44},[49,116,117],{"class":51,"line":52},[49,118,119],{"class":55},"{\n",[49,121,122,126,129,133],{"class":51,"line":59},[49,123,125],{"class":124},"snvgF","  \"model\"",[49,127,128],{"class":55},": ",[49,130,132],{"class":131},"sJ6F3","\"claude-opus-5\"",[49,134,135],{"class":55},",\n",[49,137,138,141,143,146],{"class":51,"line":65},[49,139,140],{"class":124},"  \"max_tokens\"",[49,142,128],{"class":55},[49,144,145],{"class":124},"10",[49,147,135],{"class":55},[49,149,150,153,155,158],{"class":51,"line":71},[49,151,152],{"class":124},"  \"system\"",[49,154,128],{"class":55},[49,156,157],{"class":131},"\"You are a sentiment classifier. Valid labels: POSITIVE, NEGATIVE, MIXED. Respond with exactly one label. No other text.\"",[49,159,135],{"class":55},[49,161,162,165],{"class":51,"line":78},[49,163,164],{"class":124},"  \"messages\"",[49,166,167],{"class":55},": [\n",[49,169,170,173,176,178,181,184,187,189,192],{"class":51,"line":84},[49,171,172],{"class":55},"    {",[49,174,175],{"class":124},"\"role\"",[49,177,128],{"class":55},[49,179,180],{"class":131},"\"user\"",[49,182,183],{"class":55},", ",[49,185,186],{"class":124},"\"content\"",[49,188,128],{"class":55},[49,190,191],{"class":131},"\"The build quality is fantastic but battery life is disappointing.\"",[49,193,194],{"class":55},"}\n",[49,196,197],{"class":51,"line":90},[49,198,199],{"class":55},"  ]\n",[49,201,203],{"class":51,"line":202},8,[49,204,194],{"class":55},[14,206,207,210,211,214],{},[46,208,209],{},"max_tokens: 10"," is a ",[31,212,213],{},"hard guardrail"," — even if the model ignores the instruction and starts explaining, it's truncated before it can pollute a downstream parser. Set token limits to match the output contract, not to some generous default.",[23,216,218],{"id":217},"few-shot-text-examples-vs-conversation-structure","Few-Shot: Text Examples vs Conversation Structure",[14,220,221],{},"Two equivalent ways to deliver few-shot examples — same model behavior, different ergonomics.",[102,223,225],{"id":224},"text-based-few-shot-single-message","Text-based few-shot (single message)",[36,227,228],{"language":38},[40,229,231],{"className":42,"code":230,"language":38,"meta":44,"style":44},"Classify the sentiment of each product review.\nValid labels: POSITIVE | NEGATIVE | MIXED\nRespond with exactly one label per review.\n\nReview: \"Arrived on time, works exactly as described.\"\nLabel: POSITIVE\n\nReview: \"Stopped working after two days, and support never responded.\"\nLabel: NEGATIVE\n\nReview: \"Great screen but the keyboard has dead keys after a month.\"\nLabel: MIXED\n\nReview: \"The build quality is fantastic and it feels premium, but the\nbattery life is genuinely disappointing for the price point.\"\nLabel:\n",[46,232,233,238,242,247,251,256,261,265,270,276,281,287,293,298,303,308],{"__ignoreMap":44},[49,234,235],{"class":51,"line":52},[49,236,237],{"class":55},"Classify the sentiment of each product review.\n",[49,239,240],{"class":51,"line":59},[49,241,62],{"class":55},[49,243,244],{"class":51,"line":65},[49,245,246],{"class":55},"Respond with exactly one label per review.\n",[49,248,249],{"class":51,"line":71},[49,250,75],{"emptyLinePlaceholder":74},[49,252,253],{"class":51,"line":78},[49,254,255],{"class":55},"Review: \"Arrived on time, works exactly as described.\"\n",[49,257,258],{"class":51,"line":84},[49,259,260],{"class":55},"Label: POSITIVE\n",[49,262,263],{"class":51,"line":90},[49,264,75],{"emptyLinePlaceholder":74},[49,266,267],{"class":51,"line":202},[49,268,269],{"class":55},"Review: \"Stopped working after two days, and support never responded.\"\n",[49,271,273],{"class":51,"line":272},9,[49,274,275],{"class":55},"Label: NEGATIVE\n",[49,277,279],{"class":51,"line":278},10,[49,280,75],{"emptyLinePlaceholder":74},[49,282,284],{"class":51,"line":283},11,[49,285,286],{"class":55},"Review: \"Great screen but the keyboard has dead keys after a month.\"\n",[49,288,290],{"class":51,"line":289},12,[49,291,292],{"class":55},"Label: MIXED\n",[49,294,296],{"class":51,"line":295},13,[49,297,75],{"emptyLinePlaceholder":74},[49,299,301],{"class":51,"line":300},14,[49,302,81],{"class":55},[49,304,306],{"class":51,"line":305},15,[49,307,87],{"class":55},[49,309,311],{"class":51,"line":310},16,[49,312,93],{"class":55},[14,314,315,316,319],{},"All examples and the real input live in one user message. The model sees the pattern as text and in-fills the final ",[46,317,318],{},"Label:",". Simplest to template, easiest to log as a single string.",[102,321,323],{"id":322},"conversation-structured-few-shot-json-api","Conversation-structured few-shot (JSON API)",[36,325,326],{"language":108},[40,327,329],{"className":111,"code":328,"language":108,"meta":44,"style":44},"{\n  \"model\": \"claude-opus-5\",\n  \"max_tokens\": 10,\n  \"system\": \"Classify sentiment. Valid labels: POSITIVE, NEGATIVE, MIXED. Respond with exactly one label only.\",\n  \"messages\": [\n    {\"role\": \"user\",      \"content\": \"Arrived on time, works exactly as described.\"},\n    {\"role\": \"assistant\", \"content\": \"POSITIVE\"},\n    {\"role\": \"user\",      \"content\": \"Stopped working after two days, and support never responded.\"},\n    {\"role\": \"assistant\", \"content\": \"NEGATIVE\"},\n    {\"role\": \"user\",      \"content\": \"Great screen but the keyboard has dead keys after a month.\"},\n    {\"role\": \"assistant\", \"content\": \"MIXED\"},\n    {\"role\": \"user\",      \"content\": \"The build quality is fantastic and it feels premium, but the battery life is genuinely disappointing for the price point.\"}\n  ]\n}\n",[46,330,331,335,345,355,366,372,395,417,438,459,480,501,522,526],{"__ignoreMap":44},[49,332,333],{"class":51,"line":52},[49,334,119],{"class":55},[49,336,337,339,341,343],{"class":51,"line":59},[49,338,125],{"class":124},[49,340,128],{"class":55},[49,342,132],{"class":131},[49,344,135],{"class":55},[49,346,347,349,351,353],{"class":51,"line":65},[49,348,140],{"class":124},[49,350,128],{"class":55},[49,352,145],{"class":124},[49,354,135],{"class":55},[49,356,357,359,361,364],{"class":51,"line":71},[49,358,152],{"class":124},[49,360,128],{"class":55},[49,362,363],{"class":131},"\"Classify sentiment. Valid labels: POSITIVE, NEGATIVE, MIXED. Respond with exactly one label only.\"",[49,365,135],{"class":55},[49,367,368,370],{"class":51,"line":78},[49,369,164],{"class":124},[49,371,167],{"class":55},[49,373,374,376,378,380,382,385,387,389,392],{"class":51,"line":84},[49,375,172],{"class":55},[49,377,175],{"class":124},[49,379,128],{"class":55},[49,381,180],{"class":131},[49,383,384],{"class":55},",      ",[49,386,186],{"class":124},[49,388,128],{"class":55},[49,390,391],{"class":131},"\"Arrived on time, works exactly as described.\"",[49,393,394],{"class":55},"},\n",[49,396,397,399,401,403,406,408,410,412,415],{"class":51,"line":90},[49,398,172],{"class":55},[49,400,175],{"class":124},[49,402,128],{"class":55},[49,404,405],{"class":131},"\"assistant\"",[49,407,183],{"class":55},[49,409,186],{"class":124},[49,411,128],{"class":55},[49,413,414],{"class":131},"\"POSITIVE\"",[49,416,394],{"class":55},[49,418,419,421,423,425,427,429,431,433,436],{"class":51,"line":202},[49,420,172],{"class":55},[49,422,175],{"class":124},[49,424,128],{"class":55},[49,426,180],{"class":131},[49,428,384],{"class":55},[49,430,186],{"class":124},[49,432,128],{"class":55},[49,434,435],{"class":131},"\"Stopped working after two days, and support never responded.\"",[49,437,394],{"class":55},[49,439,440,442,444,446,448,450,452,454,457],{"class":51,"line":272},[49,441,172],{"class":55},[49,443,175],{"class":124},[49,445,128],{"class":55},[49,447,405],{"class":131},[49,449,183],{"class":55},[49,451,186],{"class":124},[49,453,128],{"class":55},[49,455,456],{"class":131},"\"NEGATIVE\"",[49,458,394],{"class":55},[49,460,461,463,465,467,469,471,473,475,478],{"class":51,"line":278},[49,462,172],{"class":55},[49,464,175],{"class":124},[49,466,128],{"class":55},[49,468,180],{"class":131},[49,470,384],{"class":55},[49,472,186],{"class":124},[49,474,128],{"class":55},[49,476,477],{"class":131},"\"Great screen but the keyboard has dead keys after a month.\"",[49,479,394],{"class":55},[49,481,482,484,486,488,490,492,494,496,499],{"class":51,"line":283},[49,483,172],{"class":55},[49,485,175],{"class":124},[49,487,128],{"class":55},[49,489,405],{"class":131},[49,491,183],{"class":55},[49,493,186],{"class":124},[49,495,128],{"class":55},[49,497,498],{"class":131},"\"MIXED\"",[49,500,394],{"class":55},[49,502,503,505,507,509,511,513,515,517,520],{"class":51,"line":289},[49,504,172],{"class":55},[49,506,175],{"class":124},[49,508,128],{"class":55},[49,510,180],{"class":131},[49,512,384],{"class":55},[49,514,186],{"class":124},[49,516,128],{"class":55},[49,518,519],{"class":131},"\"The build quality is fantastic and it feels premium, but the battery life is genuinely disappointing for the price point.\"",[49,521,194],{"class":55},[49,523,524],{"class":51,"line":295},[49,525,199],{"class":55},[49,527,528],{"class":51,"line":300},[49,529,194],{"class":55},[14,531,532,533,536,537,540,541,544],{},"Each example is a genuine ",[46,534,535],{},"user","\u002F",[46,538,539],{},"assistant"," turn. The model sees prior classification ",[18,542,543],{},"decisions"," it made, not just reference text. Use this when: (a) your framework natively speaks messages (LangChain, the SDK), (b) you want the examples to feel like \"prior turns in this conversation\" rather than \"reference material,\" or (c) you're using a model that weights assistant turns more heavily as behavioral demonstrations.",[23,546,548],{"id":547},"the-accidental-pattern-trap","The Accidental-Pattern Trap",[14,550,551,552,555,556,559,560,563],{},"The most counterintuitive failure in few-shot: ",[31,553,554],{},"your examples teach a narrower rule than the one you wanted",", because all examples share an ",[18,557,558],{},"irrelevant"," surface feature that the model can't distinguish from the ",[18,561,562],{},"relevant"," pattern.",[102,565,567],{"id":566},"homogeneous-examples-wrong-generalization","Homogeneous examples → wrong generalization",[36,569,570],{"language":38},[40,571,573],{"className":42,"code":572,"language":38,"meta":44,"style":44},"Extract the customer's name and issue from the email.\nRespond as JSON: {\"name\": \"...\", \"issue\": \"...\"}\n\nEmail: \"Hi, this is John Carter, my order hasn't arrived.\"\nOutput: {\"name\": \"John Carter\", \"issue\": \"order hasn't arrived\"}\n\nEmail: \"Hello, I'm Priya Nair and my account got locked.\"\nOutput: {\"name\": \"Priya Nair\", \"issue\": \"account locked\"}\n\nEmail: \"Hey there, my name's Wei Zhang, billing charged me twice.\"\nOutput: {\"name\": \"Wei Zhang\", \"issue\": \"billed twice\"}\n\nEmail: \"So I've been a customer for 3 years and never had this problem —\nthe app crashes every time I try to upload a photo. Frustrated,\nAlex Kim\"\nOutput:\n",[46,574,575,580,585,589,594,599,603,608,613,617,622,627,631,636,641,646],{"__ignoreMap":44},[49,576,577],{"class":51,"line":52},[49,578,579],{"class":55},"Extract the customer's name and issue from the email.\n",[49,581,582],{"class":51,"line":59},[49,583,584],{"class":55},"Respond as JSON: {\"name\": \"...\", \"issue\": \"...\"}\n",[49,586,587],{"class":51,"line":65},[49,588,75],{"emptyLinePlaceholder":74},[49,590,591],{"class":51,"line":71},[49,592,593],{"class":55},"Email: \"Hi, this is John Carter, my order hasn't arrived.\"\n",[49,595,596],{"class":51,"line":78},[49,597,598],{"class":55},"Output: {\"name\": \"John Carter\", \"issue\": \"order hasn't arrived\"}\n",[49,600,601],{"class":51,"line":84},[49,602,75],{"emptyLinePlaceholder":74},[49,604,605],{"class":51,"line":90},[49,606,607],{"class":55},"Email: \"Hello, I'm Priya Nair and my account got locked.\"\n",[49,609,610],{"class":51,"line":202},[49,611,612],{"class":55},"Output: {\"name\": \"Priya Nair\", \"issue\": \"account locked\"}\n",[49,614,615],{"class":51,"line":272},[49,616,75],{"emptyLinePlaceholder":74},[49,618,619],{"class":51,"line":278},[49,620,621],{"class":55},"Email: \"Hey there, my name's Wei Zhang, billing charged me twice.\"\n",[49,623,624],{"class":51,"line":283},[49,625,626],{"class":55},"Output: {\"name\": \"Wei Zhang\", \"issue\": \"billed twice\"}\n",[49,628,629],{"class":51,"line":289},[49,630,75],{"emptyLinePlaceholder":74},[49,632,633],{"class":51,"line":295},[49,634,635],{"class":55},"Email: \"So I've been a customer for 3 years and never had this problem —\n",[49,637,638],{"class":51,"line":300},[49,639,640],{"class":55},"the app crashes every time I try to upload a photo. Frustrated,\n",[49,642,643],{"class":51,"line":305},[49,644,645],{"class":55},"Alex Kim\"\n",[49,647,648],{"class":51,"line":310},[49,649,650],{"class":55},"Output:\n",[14,652,653,656,657,660,661,664,665,668],{},[31,654,655],{},"Why it fails:"," Every example has the name at the ",[18,658,659],{},"start"," of the email. The model extracts the pattern \"name = first thing in the text.\" The real input puts the name at the ",[18,662,663],{},"end"," (a sign-off — completely realistic in customer emails). A model that over-indexed on the surface pattern has a higher chance of failing here than a ",[18,666,667],{},"zero-shot"," prompt would, because the few-shot set actively taught \"name is always first.\" The examples narrowed the generalization.",[14,670,671,674,675,677,678,680],{},[31,672,673],{},"The fix:"," Vary the ",[18,676,558],{}," surface features (where the name appears, sentence length, tone, greeting style) while keeping the ",[18,679,562],{}," task (find the name wherever it is) constant.",[23,682,684],{"id":683},"example-selection-production-example-selector","Example Selection: Production Example Selector",[14,686,687,688,691,692,695],{},"A production few-shot system doesn't hand-pick examples — it samples from a pool, prioritizing ",[31,689,690],{},"diversity"," across the features that ",[18,693,694],{},"shouldn't"," matter, so the model can't latch onto a spurious correlation.",[36,697,699],{"language":698},"python",[40,700,703],{"className":701,"code":702,"language":698,"meta":44,"style":44},"language-python shiki shiki-themes github-light github-dark","import random\nfrom dataclasses import dataclass\n\n@dataclass\nclass Example:\n    text: str\n    output: str\n    label: str          # the TRUE classification signal\n    surface_tags: list  # irrelevant features: tone, length, position, etc.\n\n# A diverse pool: varies label AND surface features independently\nEXAMPLE_POOL = [\n    Example(\"Hi, this is John Carter, my order hasn't arrived.\", '{\"name\":\"John Carter\",\"issue\":\"order not arrived\"}', \"name_at_start\", [\"polite\", \"short\"]),\n    Example(\"Frustrated, Alex Kim — app crashes on photo upload.\", '{\"name\":\"Alex Kim\",\"issue\":\"app crash on upload\"}',     \"name_at_end\",   [\"frustrated\", \"medium\"]),\n    Example(\"This is Maria Lopez from Acme. Invoice 4421 is wrong.\", '{\"name\":\"Maria Lopez\",\"issue\":\"invoice 4421 incorrect\"}', \"name_at_start\", [\"formal\", \"medium\"]),\n    Example(\"Just wanted to say — thanks, but login is broken. — Sam\", '{\"name\":\"Sam\",\"issue\":\"login broken\"}', \"name_at_end\",   [\"casual\", \"short\"]),\n    Example(\"I'm David Okafor. Two charges on my card for one order.\", '{\"name\":\"David Okafor\",\"issue\":\"duplicate charge\"}',  \"name_at_start\", [\"neutral\", \"medium\"]),\n    Example(\"Order #9912 never came. I'm Yuki Tanaka, a long-time customer.\", '{\"name\":\"Yuki Tanaka\",\"issue\":\"order #9912 not delivered\"}', \"name_at_end\", [\"neutral\", \"long\"]),\n]\n\ndef select_diverse_examples(pool: list[Example], k: int = 3) -> list[Example]:\n    \"\"\"Greedy max-coverage: pick examples that maximize surface-feature diversity.\n    Ensures the model sees name_at_start AND name_at_end, polite AND frustrated,\n    short AND long — so no single surface feature correlates with the task.\"\"\"\n    selected: list[Example] = []\n    covered_tags: set = set()\n    # First pass: guarantee label coverage (at least one of each structural type)\n    seen_labels: set = set()\n    for ex in pool:\n        if ex.label not in seen_labels:\n            selected.append(ex)\n            seen_labels.add(ex.label)\n            covered_tags.update(ex.surface_tags)\n    # Remaining picks: greedily maximize NEW surface tags\n    remaining = [e for e in pool if e not in selected]\n    while len(selected) \u003C k and remaining:\n        remaining.sort(key=lambda e: len(set(e.surface_tags) - covered_tags), reverse=True)\n        best = remaining.pop(0)\n        selected.append(best)\n        covered_tags.update(best.surface_tags)\n    return selected[:k]\n\ndef build_few_shot_prompt(task_input: str, examples: list[Example]) -> str:\n    \"\"\"Assemble the prompt with selected examples + real input.\"\"\"\n    header = 'Extract the customer\\'s name and issue. Respond as JSON: {\"name\":\"...\",\"issue\":\"...\"}\\n'\n    body = \"\"\n    for ex in examples:\n        body += f'\\nEmail: \"{ex.text}\"\\nOutput: {ex.output}\\n'\n    body += f'\\nEmail: \"{task_input}\"\\nOutput:'\n    return header + body\n\n# Usage: fresh diverse selection per request (or cache per session)\nselected = select_diverse_examples(EXAMPLE_POOL, k=3)\nprompt = build_few_shot_prompt(\"The dashboard won't load. Regards, Fatima\", selected)\nprint(prompt)\n",[46,704,705,714,727,731,737,748,756,763,775,786,790,795,806,838,869,896,923,952,980,986,991,1014,1020,1026,1032,1044,1061,1067,1081,1096,1114,1120,1126,1132,1138,1172,1196,1240,1256,1262,1268,1277,1282,1302,1308,1331,1342,1354,1401,1430,1444,1449,1455,1480,1497],{"__ignoreMap":44},[49,706,707,711],{"class":51,"line":52},[49,708,710],{"class":709},"svdQ7","import",[49,712,713],{"class":55}," random\n",[49,715,716,719,722,724],{"class":51,"line":59},[49,717,718],{"class":709},"from",[49,720,721],{"class":55}," dataclasses ",[49,723,710],{"class":709},[49,725,726],{"class":55}," dataclass\n",[49,728,729],{"class":51,"line":65},[49,730,75],{"emptyLinePlaceholder":74},[49,732,733],{"class":51,"line":71},[49,734,736],{"class":735},"sIsaT","@dataclass\n",[49,738,739,742,745],{"class":51,"line":78},[49,740,741],{"class":709},"class",[49,743,744],{"class":735}," Example",[49,746,747],{"class":55},":\n",[49,749,750,753],{"class":51,"line":84},[49,751,752],{"class":55},"    text: ",[49,754,755],{"class":124},"str\n",[49,757,758,761],{"class":51,"line":90},[49,759,760],{"class":55},"    output: ",[49,762,755],{"class":124},[49,764,765,768,771],{"class":51,"line":202},[49,766,767],{"class":55},"    label: ",[49,769,770],{"class":124},"str",[49,772,774],{"class":773},"sdCPZ","          # the TRUE classification signal\n",[49,776,777,780,783],{"class":51,"line":272},[49,778,779],{"class":55},"    surface_tags: ",[49,781,782],{"class":124},"list",[49,784,785],{"class":773},"  # irrelevant features: tone, length, position, etc.\n",[49,787,788],{"class":51,"line":278},[49,789,75],{"emptyLinePlaceholder":74},[49,791,792],{"class":51,"line":283},[49,793,794],{"class":773},"# A diverse pool: varies label AND surface features independently\n",[49,796,797,800,803],{"class":51,"line":289},[49,798,799],{"class":124},"EXAMPLE_POOL",[49,801,802],{"class":709}," =",[49,804,805],{"class":55}," [\n",[49,807,808,811,814,816,819,821,824,827,830,832,835],{"class":51,"line":295},[49,809,810],{"class":55},"    Example(",[49,812,813],{"class":131},"\"Hi, this is John Carter, my order hasn't arrived.\"",[49,815,183],{"class":55},[49,817,818],{"class":131},"'{\"name\":\"John Carter\",\"issue\":\"order not arrived\"}'",[49,820,183],{"class":55},[49,822,823],{"class":131},"\"name_at_start\"",[49,825,826],{"class":55},", [",[49,828,829],{"class":131},"\"polite\"",[49,831,183],{"class":55},[49,833,834],{"class":131},"\"short\"",[49,836,837],{"class":55},"]),\n",[49,839,840,842,845,847,850,853,856,859,862,864,867],{"class":51,"line":300},[49,841,810],{"class":55},[49,843,844],{"class":131},"\"Frustrated, Alex Kim — app crashes on photo upload.\"",[49,846,183],{"class":55},[49,848,849],{"class":131},"'{\"name\":\"Alex Kim\",\"issue\":\"app crash on upload\"}'",[49,851,852],{"class":55},",     ",[49,854,855],{"class":131},"\"name_at_end\"",[49,857,858],{"class":55},",   [",[49,860,861],{"class":131},"\"frustrated\"",[49,863,183],{"class":55},[49,865,866],{"class":131},"\"medium\"",[49,868,837],{"class":55},[49,870,871,873,876,878,881,883,885,887,890,892,894],{"class":51,"line":305},[49,872,810],{"class":55},[49,874,875],{"class":131},"\"This is Maria Lopez from Acme. Invoice 4421 is wrong.\"",[49,877,183],{"class":55},[49,879,880],{"class":131},"'{\"name\":\"Maria Lopez\",\"issue\":\"invoice 4421 incorrect\"}'",[49,882,183],{"class":55},[49,884,823],{"class":131},[49,886,826],{"class":55},[49,888,889],{"class":131},"\"formal\"",[49,891,183],{"class":55},[49,893,866],{"class":131},[49,895,837],{"class":55},[49,897,898,900,903,905,908,910,912,914,917,919,921],{"class":51,"line":310},[49,899,810],{"class":55},[49,901,902],{"class":131},"\"Just wanted to say — thanks, but login is broken. — Sam\"",[49,904,183],{"class":55},[49,906,907],{"class":131},"'{\"name\":\"Sam\",\"issue\":\"login broken\"}'",[49,909,183],{"class":55},[49,911,855],{"class":131},[49,913,858],{"class":55},[49,915,916],{"class":131},"\"casual\"",[49,918,183],{"class":55},[49,920,834],{"class":131},[49,922,837],{"class":55},[49,924,926,928,931,933,936,939,941,943,946,948,950],{"class":51,"line":925},17,[49,927,810],{"class":55},[49,929,930],{"class":131},"\"I'm David Okafor. Two charges on my card for one order.\"",[49,932,183],{"class":55},[49,934,935],{"class":131},"'{\"name\":\"David Okafor\",\"issue\":\"duplicate charge\"}'",[49,937,938],{"class":55},",  ",[49,940,823],{"class":131},[49,942,826],{"class":55},[49,944,945],{"class":131},"\"neutral\"",[49,947,183],{"class":55},[49,949,866],{"class":131},[49,951,837],{"class":55},[49,953,955,957,960,962,965,967,969,971,973,975,978],{"class":51,"line":954},18,[49,956,810],{"class":55},[49,958,959],{"class":131},"\"Order #9912 never came. I'm Yuki Tanaka, a long-time customer.\"",[49,961,183],{"class":55},[49,963,964],{"class":131},"'{\"name\":\"Yuki Tanaka\",\"issue\":\"order #9912 not delivered\"}'",[49,966,183],{"class":55},[49,968,855],{"class":131},[49,970,826],{"class":55},[49,972,945],{"class":131},[49,974,183],{"class":55},[49,976,977],{"class":131},"\"long\"",[49,979,837],{"class":55},[49,981,983],{"class":51,"line":982},19,[49,984,985],{"class":55},"]\n",[49,987,989],{"class":51,"line":988},20,[49,990,75],{"emptyLinePlaceholder":74},[49,992,994,997,1000,1003,1006,1008,1011],{"class":51,"line":993},21,[49,995,996],{"class":709},"def",[49,998,999],{"class":735}," select_diverse_examples",[49,1001,1002],{"class":55},"(pool: list[Example], k: ",[49,1004,1005],{"class":124},"int",[49,1007,802],{"class":709},[49,1009,1010],{"class":124}," 3",[49,1012,1013],{"class":55},") -> list[Example]:\n",[49,1015,1017],{"class":51,"line":1016},22,[49,1018,1019],{"class":131},"    \"\"\"Greedy max-coverage: pick examples that maximize surface-feature diversity.\n",[49,1021,1023],{"class":51,"line":1022},23,[49,1024,1025],{"class":131},"    Ensures the model sees name_at_start AND name_at_end, polite AND frustrated,\n",[49,1027,1029],{"class":51,"line":1028},24,[49,1030,1031],{"class":131},"    short AND long — so no single surface feature correlates with the task.\"\"\"\n",[49,1033,1035,1038,1041],{"class":51,"line":1034},25,[49,1036,1037],{"class":55},"    selected: list[Example] ",[49,1039,1040],{"class":709},"=",[49,1042,1043],{"class":55}," []\n",[49,1045,1047,1050,1053,1055,1058],{"class":51,"line":1046},26,[49,1048,1049],{"class":55},"    covered_tags: ",[49,1051,1052],{"class":124},"set",[49,1054,802],{"class":709},[49,1056,1057],{"class":124}," set",[49,1059,1060],{"class":55},"()\n",[49,1062,1064],{"class":51,"line":1063},27,[49,1065,1066],{"class":773},"    # First pass: guarantee label coverage (at least one of each structural type)\n",[49,1068,1070,1073,1075,1077,1079],{"class":51,"line":1069},28,[49,1071,1072],{"class":55},"    seen_labels: ",[49,1074,1052],{"class":124},[49,1076,802],{"class":709},[49,1078,1057],{"class":124},[49,1080,1060],{"class":55},[49,1082,1084,1087,1090,1093],{"class":51,"line":1083},29,[49,1085,1086],{"class":709},"    for",[49,1088,1089],{"class":55}," ex ",[49,1091,1092],{"class":709},"in",[49,1094,1095],{"class":55}," pool:\n",[49,1097,1099,1102,1105,1108,1111],{"class":51,"line":1098},30,[49,1100,1101],{"class":709},"        if",[49,1103,1104],{"class":55}," ex.label ",[49,1106,1107],{"class":709},"not",[49,1109,1110],{"class":709}," in",[49,1112,1113],{"class":55}," seen_labels:\n",[49,1115,1117],{"class":51,"line":1116},31,[49,1118,1119],{"class":55},"            selected.append(ex)\n",[49,1121,1123],{"class":51,"line":1122},32,[49,1124,1125],{"class":55},"            seen_labels.add(ex.label)\n",[49,1127,1129],{"class":51,"line":1128},33,[49,1130,1131],{"class":55},"            covered_tags.update(ex.surface_tags)\n",[49,1133,1135],{"class":51,"line":1134},34,[49,1136,1137],{"class":773},"    # Remaining picks: greedily maximize NEW surface tags\n",[49,1139,1141,1144,1146,1149,1152,1155,1157,1160,1163,1165,1167,1169],{"class":51,"line":1140},35,[49,1142,1143],{"class":55},"    remaining ",[49,1145,1040],{"class":709},[49,1147,1148],{"class":55}," [e ",[49,1150,1151],{"class":709},"for",[49,1153,1154],{"class":55}," e ",[49,1156,1092],{"class":709},[49,1158,1159],{"class":55}," pool ",[49,1161,1162],{"class":709},"if",[49,1164,1154],{"class":55},[49,1166,1107],{"class":709},[49,1168,1110],{"class":709},[49,1170,1171],{"class":55}," selected]\n",[49,1173,1175,1178,1181,1184,1187,1190,1193],{"class":51,"line":1174},36,[49,1176,1177],{"class":709},"    while",[49,1179,1180],{"class":124}," len",[49,1182,1183],{"class":55},"(selected) ",[49,1185,1186],{"class":709},"\u003C",[49,1188,1189],{"class":55}," k ",[49,1191,1192],{"class":709},"and",[49,1194,1195],{"class":55}," remaining:\n",[49,1197,1199,1202,1206,1209,1212,1215,1218,1220,1223,1226,1229,1232,1234,1237],{"class":51,"line":1198},37,[49,1200,1201],{"class":55},"        remaining.sort(",[49,1203,1205],{"class":1204},"sCrzJ","key",[49,1207,1208],{"class":709},"=lambda",[49,1210,1211],{"class":55}," e: ",[49,1213,1214],{"class":124},"len",[49,1216,1217],{"class":55},"(",[49,1219,1052],{"class":124},[49,1221,1222],{"class":55},"(e.surface_tags) ",[49,1224,1225],{"class":709},"-",[49,1227,1228],{"class":55}," covered_tags), ",[49,1230,1231],{"class":1204},"reverse",[49,1233,1040],{"class":709},[49,1235,1236],{"class":124},"True",[49,1238,1239],{"class":55},")\n",[49,1241,1243,1246,1248,1251,1254],{"class":51,"line":1242},38,[49,1244,1245],{"class":55},"        best ",[49,1247,1040],{"class":709},[49,1249,1250],{"class":55}," remaining.pop(",[49,1252,1253],{"class":124},"0",[49,1255,1239],{"class":55},[49,1257,1259],{"class":51,"line":1258},39,[49,1260,1261],{"class":55},"        selected.append(best)\n",[49,1263,1265],{"class":51,"line":1264},40,[49,1266,1267],{"class":55},"        covered_tags.update(best.surface_tags)\n",[49,1269,1271,1274],{"class":51,"line":1270},41,[49,1272,1273],{"class":709},"    return",[49,1275,1276],{"class":55}," selected[:k]\n",[49,1278,1280],{"class":51,"line":1279},42,[49,1281,75],{"emptyLinePlaceholder":74},[49,1283,1285,1287,1290,1293,1295,1298,1300],{"class":51,"line":1284},43,[49,1286,996],{"class":709},[49,1288,1289],{"class":735}," build_few_shot_prompt",[49,1291,1292],{"class":55},"(task_input: ",[49,1294,770],{"class":124},[49,1296,1297],{"class":55},", examples: list[Example]) -> ",[49,1299,770],{"class":124},[49,1301,747],{"class":55},[49,1303,1305],{"class":51,"line":1304},44,[49,1306,1307],{"class":131},"    \"\"\"Assemble the prompt with selected examples + real input.\"\"\"\n",[49,1309,1311,1314,1316,1319,1322,1325,1328],{"class":51,"line":1310},45,[49,1312,1313],{"class":55},"    header ",[49,1315,1040],{"class":709},[49,1317,1318],{"class":131}," 'Extract the customer",[49,1320,1321],{"class":124},"\\'",[49,1323,1324],{"class":131},"s name and issue. Respond as JSON: {\"name\":\"...\",\"issue\":\"...\"}",[49,1326,1327],{"class":124},"\\n",[49,1329,1330],{"class":131},"'\n",[49,1332,1334,1337,1339],{"class":51,"line":1333},46,[49,1335,1336],{"class":55},"    body ",[49,1338,1040],{"class":709},[49,1340,1341],{"class":131}," \"\"\n",[49,1343,1345,1347,1349,1351],{"class":51,"line":1344},47,[49,1346,1086],{"class":709},[49,1348,1089],{"class":55},[49,1350,1092],{"class":709},[49,1352,1353],{"class":55}," examples:\n",[49,1355,1357,1360,1363,1366,1369,1371,1374,1377,1380,1383,1386,1388,1391,1393,1396,1399],{"class":51,"line":1356},48,[49,1358,1359],{"class":55},"        body ",[49,1361,1362],{"class":709},"+=",[49,1364,1365],{"class":709}," f",[49,1367,1368],{"class":131},"'",[49,1370,1327],{"class":124},[49,1372,1373],{"class":131},"Email: \"",[49,1375,1376],{"class":124},"{",[49,1378,1379],{"class":55},"ex.text",[49,1381,1382],{"class":124},"}",[49,1384,1385],{"class":131},"\"",[49,1387,1327],{"class":124},[49,1389,1390],{"class":131},"Output: ",[49,1392,1376],{"class":124},[49,1394,1395],{"class":55},"ex.output",[49,1397,1398],{"class":124},"}\\n",[49,1400,1330],{"class":131},[49,1402,1404,1406,1408,1410,1412,1414,1416,1418,1421,1423,1425,1427],{"class":51,"line":1403},49,[49,1405,1336],{"class":55},[49,1407,1362],{"class":709},[49,1409,1365],{"class":709},[49,1411,1368],{"class":131},[49,1413,1327],{"class":124},[49,1415,1373],{"class":131},[49,1417,1376],{"class":124},[49,1419,1420],{"class":55},"task_input",[49,1422,1382],{"class":124},[49,1424,1385],{"class":131},[49,1426,1327],{"class":124},[49,1428,1429],{"class":131},"Output:'\n",[49,1431,1433,1435,1438,1441],{"class":51,"line":1432},50,[49,1434,1273],{"class":709},[49,1436,1437],{"class":55}," header ",[49,1439,1440],{"class":709},"+",[49,1442,1443],{"class":55}," body\n",[49,1445,1447],{"class":51,"line":1446},51,[49,1448,75],{"emptyLinePlaceholder":74},[49,1450,1452],{"class":51,"line":1451},52,[49,1453,1454],{"class":773},"# Usage: fresh diverse selection per request (or cache per session)\n",[49,1456,1458,1461,1463,1466,1468,1470,1473,1475,1478],{"class":51,"line":1457},53,[49,1459,1460],{"class":55},"selected ",[49,1462,1040],{"class":709},[49,1464,1465],{"class":55}," select_diverse_examples(",[49,1467,799],{"class":124},[49,1469,183],{"class":55},[49,1471,1472],{"class":1204},"k",[49,1474,1040],{"class":709},[49,1476,1477],{"class":124},"3",[49,1479,1239],{"class":55},[49,1481,1483,1486,1488,1491,1494],{"class":51,"line":1482},54,[49,1484,1485],{"class":55},"prompt ",[49,1487,1040],{"class":709},[49,1489,1490],{"class":55}," build_few_shot_prompt(",[49,1492,1493],{"class":131},"\"The dashboard won't load. Regards, Fatima\"",[49,1495,1496],{"class":55},", selected)\n",[49,1498,1500,1503],{"class":51,"line":1499},55,[49,1501,1502],{"class":124},"print",[49,1504,1505],{"class":55},"(prompt)\n",[14,1507,1508,1509,1512,1513,1516,1517,1520,1521,1524,1525,1528],{},"The selector guarantees ",[31,1510,1511],{},"label coverage"," (at least one ",[46,1514,1515],{},"name_at_start"," and one ",[46,1518,1519],{},"name_at_end",") then greedily maximizes ",[31,1522,1523],{},"surface-feature diversity"," (tone, length, formality). The model now sees that the name can appear ",[18,1526,1527],{},"anywhere"," — the spurious \"name is always first\" pattern is impossible to form.",[23,1530,1532],{"id":1531},"example-ordering-shuffling-to-avoid-positional-bias","Example Ordering: Shuffling to Avoid Positional Bias",[14,1534,1535,1536,1539,1540,1543,1544,1547],{},"The example ",[31,1537,1538],{},"closest to the real input"," has outsized influence (recency effect). If examples are sorted or patterned, the model can pick up on ",[18,1541,1542],{},"positional"," patterns instead of ",[18,1545,1546],{},"content"," patterns.",[36,1549,1550],{"language":698},[40,1551,1553],{"className":701,"code":1552,"language":698,"meta":44,"style":44},"import random\n\ndef order_examples(examples: list[Example], strategy: str = \"shuffle_hard_last\") -> list[Example]:\n    \"\"\"Order examples to avoid positional bias.\n    \n    Strategies:\n      'shuffle'           — random order; no positional correlation with labels\n      'shuffle_hard_last' — shuffle, but place the trickiest example last\n                            (closest to real input → maximum recency influence)\n      'interleave'        — alternate labels so no two adjacent share a label\n    \"\"\"\n    if strategy == \"shuffle\":\n        shuffled = examples[:]\n        random.shuffle(shuffled)\n        return shuffled\n    \n    if strategy == \"shuffle_hard_last\":\n        # Hardest = most surface features that could mislead (most surface_tags)\n        ranked = sorted(examples, key=lambda e: len(e.surface_tags))\n        hardest = ranked[-1]\n        rest = [e for e in examples if e is not hardest]\n        random.shuffle(rest)\n        return rest + [hardest]\n    \n    if strategy == \"interleave\":\n        # Sort by label, then deal into alternating slots\n        by_label: dict = {}\n        for ex in examples:\n            by_label.setdefault(ex.label, []).append(ex)\n        interleaved: list = []\n        max_len = max(len(v) for v in by_label.values())\n        for i in range(max_len):\n            for label in by_label:\n                if i \u003C len(by_label[label]):\n                    interleaved.append(by_label[label][i])\n        return interleaved\n    \n    return examples\n\n# Production: re-shuffle per request so a fixed order can't become a pattern\nordered = order_examples(selected, strategy=\"shuffle_hard_last\")\nprompt = build_few_shot_prompt(\"Dashboard won't load. Regards, Fatima\", ordered)\n",[46,1554,1555,1561,1565,1584,1589,1594,1599,1604,1609,1614,1619,1624,1640,1650,1655,1663,1667,1679,1684,1708,1725,1755,1760,1772,1776,1789,1794,1807,1818,1823,1834,1861,1876,1889,1903,1908,1915,1919,1926,1930,1935,1955],{"__ignoreMap":44},[49,1556,1557,1559],{"class":51,"line":52},[49,1558,710],{"class":709},[49,1560,713],{"class":55},[49,1562,1563],{"class":51,"line":59},[49,1564,75],{"emptyLinePlaceholder":74},[49,1566,1567,1569,1572,1575,1577,1579,1582],{"class":51,"line":65},[49,1568,996],{"class":709},[49,1570,1571],{"class":735}," order_examples",[49,1573,1574],{"class":55},"(examples: list[Example], strategy: ",[49,1576,770],{"class":124},[49,1578,802],{"class":709},[49,1580,1581],{"class":131}," \"shuffle_hard_last\"",[49,1583,1013],{"class":55},[49,1585,1586],{"class":51,"line":71},[49,1587,1588],{"class":131},"    \"\"\"Order examples to avoid positional bias.\n",[49,1590,1591],{"class":51,"line":78},[49,1592,1593],{"class":131},"    \n",[49,1595,1596],{"class":51,"line":84},[49,1597,1598],{"class":131},"    Strategies:\n",[49,1600,1601],{"class":51,"line":90},[49,1602,1603],{"class":131},"      'shuffle'           — random order; no positional correlation with labels\n",[49,1605,1606],{"class":51,"line":202},[49,1607,1608],{"class":131},"      'shuffle_hard_last' — shuffle, but place the trickiest example last\n",[49,1610,1611],{"class":51,"line":272},[49,1612,1613],{"class":131},"                            (closest to real input → maximum recency influence)\n",[49,1615,1616],{"class":51,"line":278},[49,1617,1618],{"class":131},"      'interleave'        — alternate labels so no two adjacent share a label\n",[49,1620,1621],{"class":51,"line":283},[49,1622,1623],{"class":131},"    \"\"\"\n",[49,1625,1626,1629,1632,1635,1638],{"class":51,"line":289},[49,1627,1628],{"class":709},"    if",[49,1630,1631],{"class":55}," strategy ",[49,1633,1634],{"class":709},"==",[49,1636,1637],{"class":131}," \"shuffle\"",[49,1639,747],{"class":55},[49,1641,1642,1645,1647],{"class":51,"line":295},[49,1643,1644],{"class":55},"        shuffled ",[49,1646,1040],{"class":709},[49,1648,1649],{"class":55}," examples[:]\n",[49,1651,1652],{"class":51,"line":300},[49,1653,1654],{"class":55},"        random.shuffle(shuffled)\n",[49,1656,1657,1660],{"class":51,"line":305},[49,1658,1659],{"class":709},"        return",[49,1661,1662],{"class":55}," shuffled\n",[49,1664,1665],{"class":51,"line":310},[49,1666,1593],{"class":55},[49,1668,1669,1671,1673,1675,1677],{"class":51,"line":925},[49,1670,1628],{"class":709},[49,1672,1631],{"class":55},[49,1674,1634],{"class":709},[49,1676,1581],{"class":131},[49,1678,747],{"class":55},[49,1680,1681],{"class":51,"line":954},[49,1682,1683],{"class":773},"        # Hardest = most surface features that could mislead (most surface_tags)\n",[49,1685,1686,1689,1691,1694,1697,1699,1701,1703,1705],{"class":51,"line":982},[49,1687,1688],{"class":55},"        ranked ",[49,1690,1040],{"class":709},[49,1692,1693],{"class":124}," sorted",[49,1695,1696],{"class":55},"(examples, ",[49,1698,1205],{"class":1204},[49,1700,1208],{"class":709},[49,1702,1211],{"class":55},[49,1704,1214],{"class":124},[49,1706,1707],{"class":55},"(e.surface_tags))\n",[49,1709,1710,1713,1715,1718,1720,1723],{"class":51,"line":988},[49,1711,1712],{"class":55},"        hardest ",[49,1714,1040],{"class":709},[49,1716,1717],{"class":55}," ranked[",[49,1719,1225],{"class":709},[49,1721,1722],{"class":124},"1",[49,1724,985],{"class":55},[49,1726,1727,1730,1732,1734,1736,1738,1740,1743,1745,1747,1749,1752],{"class":51,"line":993},[49,1728,1729],{"class":55},"        rest ",[49,1731,1040],{"class":709},[49,1733,1148],{"class":55},[49,1735,1151],{"class":709},[49,1737,1154],{"class":55},[49,1739,1092],{"class":709},[49,1741,1742],{"class":55}," examples ",[49,1744,1162],{"class":709},[49,1746,1154],{"class":55},[49,1748,99],{"class":709},[49,1750,1751],{"class":709}," not",[49,1753,1754],{"class":55}," hardest]\n",[49,1756,1757],{"class":51,"line":1016},[49,1758,1759],{"class":55},"        random.shuffle(rest)\n",[49,1761,1762,1764,1767,1769],{"class":51,"line":1022},[49,1763,1659],{"class":709},[49,1765,1766],{"class":55}," rest ",[49,1768,1440],{"class":709},[49,1770,1771],{"class":55}," [hardest]\n",[49,1773,1774],{"class":51,"line":1028},[49,1775,1593],{"class":55},[49,1777,1778,1780,1782,1784,1787],{"class":51,"line":1034},[49,1779,1628],{"class":709},[49,1781,1631],{"class":55},[49,1783,1634],{"class":709},[49,1785,1786],{"class":131}," \"interleave\"",[49,1788,747],{"class":55},[49,1790,1791],{"class":51,"line":1046},[49,1792,1793],{"class":773},"        # Sort by label, then deal into alternating slots\n",[49,1795,1796,1799,1802,1804],{"class":51,"line":1063},[49,1797,1798],{"class":55},"        by_label: ",[49,1800,1801],{"class":124},"dict",[49,1803,802],{"class":709},[49,1805,1806],{"class":55}," {}\n",[49,1808,1809,1812,1814,1816],{"class":51,"line":1069},[49,1810,1811],{"class":709},"        for",[49,1813,1089],{"class":55},[49,1815,1092],{"class":709},[49,1817,1353],{"class":55},[49,1819,1820],{"class":51,"line":1083},[49,1821,1822],{"class":55},"            by_label.setdefault(ex.label, []).append(ex)\n",[49,1824,1825,1828,1830,1832],{"class":51,"line":1098},[49,1826,1827],{"class":55},"        interleaved: ",[49,1829,782],{"class":124},[49,1831,802],{"class":709},[49,1833,1043],{"class":55},[49,1835,1836,1839,1841,1844,1846,1848,1851,1853,1856,1858],{"class":51,"line":1116},[49,1837,1838],{"class":55},"        max_len ",[49,1840,1040],{"class":709},[49,1842,1843],{"class":124}," max",[49,1845,1217],{"class":55},[49,1847,1214],{"class":124},[49,1849,1850],{"class":55},"(v) ",[49,1852,1151],{"class":709},[49,1854,1855],{"class":55}," v ",[49,1857,1092],{"class":709},[49,1859,1860],{"class":55}," by_label.values())\n",[49,1862,1863,1865,1868,1870,1873],{"class":51,"line":1122},[49,1864,1811],{"class":709},[49,1866,1867],{"class":55}," i ",[49,1869,1092],{"class":709},[49,1871,1872],{"class":124}," range",[49,1874,1875],{"class":55},"(max_len):\n",[49,1877,1878,1881,1884,1886],{"class":51,"line":1128},[49,1879,1880],{"class":709},"            for",[49,1882,1883],{"class":55}," label ",[49,1885,1092],{"class":709},[49,1887,1888],{"class":55}," by_label:\n",[49,1890,1891,1894,1896,1898,1900],{"class":51,"line":1134},[49,1892,1893],{"class":709},"                if",[49,1895,1867],{"class":55},[49,1897,1186],{"class":709},[49,1899,1180],{"class":124},[49,1901,1902],{"class":55},"(by_label[label]):\n",[49,1904,1905],{"class":51,"line":1140},[49,1906,1907],{"class":55},"                    interleaved.append(by_label[label][i])\n",[49,1909,1910,1912],{"class":51,"line":1174},[49,1911,1659],{"class":709},[49,1913,1914],{"class":55}," interleaved\n",[49,1916,1917],{"class":51,"line":1198},[49,1918,1593],{"class":55},[49,1920,1921,1923],{"class":51,"line":1242},[49,1922,1273],{"class":709},[49,1924,1925],{"class":55}," examples\n",[49,1927,1928],{"class":51,"line":1258},[49,1929,75],{"emptyLinePlaceholder":74},[49,1931,1932],{"class":51,"line":1264},[49,1933,1934],{"class":773},"# Production: re-shuffle per request so a fixed order can't become a pattern\n",[49,1936,1937,1940,1942,1945,1948,1950,1953],{"class":51,"line":1270},[49,1938,1939],{"class":55},"ordered ",[49,1941,1040],{"class":709},[49,1943,1944],{"class":55}," order_examples(selected, ",[49,1946,1947],{"class":1204},"strategy",[49,1949,1040],{"class":709},[49,1951,1952],{"class":131},"\"shuffle_hard_last\"",[49,1954,1239],{"class":55},[49,1956,1957,1959,1961,1963,1966],{"class":51,"line":1279},[49,1958,1485],{"class":55},[49,1960,1040],{"class":709},[49,1962,1490],{"class":55},[49,1964,1965],{"class":131},"\"Dashboard won't load. Regards, Fatima\"",[49,1967,1968],{"class":55},", ordered)\n",[14,1970,1971,1978,1979,1982,1983,1986],{},[31,1972,1973,1974,1977],{},"Why ",[46,1975,1976],{},"shuffle_hard_last",":"," The recency effect means the last example is weighted heaviest. Placing the ",[18,1980,1981],{},"hardest"," (most surface-feature-rich, most likely to mislead) example last ensures the model's freshest reference is the one that best demonstrates \"ignore surface features, focus on the task.\" Placing the ",[18,1984,1985],{},"easiest"," example last teaches the model that inputs are always easy.",[23,1988,1990],{"id":1989},"diminishing-returns-example-count-vs-effect","Diminishing Returns: Example Count vs Effect",[14,1992,1993,1994,1997],{},"The jump from 0→2 examples is steep. Past ~5, returns flatten — and can ",[18,1995,1996],{},"decline"," if added examples are homogeneous or introduce noise.",[1999,2000,2001,2017],"table",{},[2002,2003,2004],"thead",{},[2005,2006,2007,2011,2014],"tr",{},[2008,2009,2010],"th",{},"Examples",[2008,2012,2013],{},"Typical Effect",[2008,2015,2016],{},"When to Use",[2018,2019,2020,2031,2045,2056,2067],"tbody",{},[2005,2021,2022,2025,2028],{},[2023,2024,1253],"td",{},[2023,2026,2027],{},"Baseline. Sufficient for common, well-specified tasks (sentiment, summarization, translation).",[2023,2029,2030],{},"Default starting point. Always test here first.",[2005,2032,2033,2035,2042],{},[2023,2034,1722],{},[2023,2036,2037,2038,2041],{},"Meaningful jump — establishes format + register. ",[31,2039,2040],{},"Risk:"," with one example, the model can't distinguish \"general rule\" from \"incidental detail.\"",[2023,2043,2044],{},"Only if the task is dead simple (format-only).",[2005,2046,2047,2050,2053],{},[2023,2048,2049],{},"2–5",[2023,2051,2052],{},"Sweet spot for most classification\u002Fextraction\u002Fformatting. Enough variation to show the pattern without bloating tokens.",[2023,2054,2055],{},"Majority of production few-shot prompts.",[2005,2057,2058,2061,2064],{},[2023,2059,2060],{},"5–20",[2023,2062,2063],{},"Helpful for many-category tasks or tasks with many distinct edge cases. Diminishing returns per example.",[2023,2065,2066],{},"Multi-label classification, complex extraction schemas.",[2005,2068,2069,2072,2075],{},[2023,2070,2071],{},"20+",[2023,2073,2074],{},"Rarely worth it in-context. Token cost dominates. If you need this many, consider retrieval (RAG), a lookup table, or fine-tuning.",[2023,2076,2077],{},"Almost never in-context. Move to RAG or fine-tune.",[14,2079,2080,2083,2084,2087],{},[31,2081,2082],{},"The steepest jump is always 0 → 1–2."," Past five well-chosen diverse examples, spend effort improving ",[18,2085,2086],{},"which"," examples you include, not adding more.",[23,2089,2091],{"id":2090},"anti-pattern-homogeneous-examples-failing-on-low-input","Anti-Pattern: Homogeneous Examples Failing on Low Input",[14,2093,2094],{},"A team classifies support tickets by urgency (LOW, MEDIUM, HIGH). All three examples are from a single outage — all HIGH, all contain \"urgent\":",[36,2096,2097],{"language":38},[40,2098,2100],{"className":42,"code":2099,"language":38,"meta":44,"style":44},"Classify the urgency of the ticket as LOW, MEDIUM, or HIGH.\n\nTicket: \"URGENT — the entire dashboard is down for our whole team, please help ASAP\"\nUrgency: HIGH\n\nTicket: \"This is urgent, we can't process any orders right now\"\nUrgency: HIGH\n\nTicket: \"Urgent!! Nothing is loading, this is a total outage on our end\"\nUrgency: HIGH\n\nTicket: \"Not sure if this matters, but the export button seems to download\na file with the wrong date format — not blocking us, just noticed it\"\nUrgency:\n",[46,2101,2102,2107,2111,2116,2121,2125,2130,2134,2138,2143,2147,2151,2156,2161],{"__ignoreMap":44},[49,2103,2104],{"class":51,"line":52},[49,2105,2106],{"class":55},"Classify the urgency of the ticket as LOW, MEDIUM, or HIGH.\n",[49,2108,2109],{"class":51,"line":59},[49,2110,75],{"emptyLinePlaceholder":74},[49,2112,2113],{"class":51,"line":65},[49,2114,2115],{"class":55},"Ticket: \"URGENT — the entire dashboard is down for our whole team, please help ASAP\"\n",[49,2117,2118],{"class":51,"line":71},[49,2119,2120],{"class":55},"Urgency: HIGH\n",[49,2122,2123],{"class":51,"line":78},[49,2124,75],{"emptyLinePlaceholder":74},[49,2126,2127],{"class":51,"line":84},[49,2128,2129],{"class":55},"Ticket: \"This is urgent, we can't process any orders right now\"\n",[49,2131,2132],{"class":51,"line":90},[49,2133,2120],{"class":55},[49,2135,2136],{"class":51,"line":202},[49,2137,75],{"emptyLinePlaceholder":74},[49,2139,2140],{"class":51,"line":272},[49,2141,2142],{"class":55},"Ticket: \"Urgent!! Nothing is loading, this is a total outage on our end\"\n",[49,2144,2145],{"class":51,"line":278},[49,2146,2120],{"class":55},[49,2148,2149],{"class":51,"line":283},[49,2150,75],{"emptyLinePlaceholder":74},[49,2152,2153],{"class":51,"line":289},[49,2154,2155],{"class":55},"Ticket: \"Not sure if this matters, but the export button seems to download\n",[49,2157,2158],{"class":51,"line":295},[49,2159,2160],{"class":55},"a file with the wrong date format — not blocking us, just noticed it\"\n",[49,2162,2163],{"class":51,"line":300},[49,2164,2165],{"class":55},"Urgency:\n",[14,2167,2168,2171],{},[31,2169,2170],{},"What goes wrong:"," Zero label diversity — the model has never seen a LOW or MEDIUM example. It can only infer urgency by matching lexical surface features (\"urgent,\" exclamation marks, emphatic tone) that co-occurred with HIGH in this sample. The real ticket is a textbook LOW (non-blocking, minor, polite) — but because the model learned \"emphatic = HIGH\" and has no concept of what LOW looks like, it classifies LOW inputs as MEDIUM or HIGH.",[14,2173,2174,2176],{},[31,2175,673],{}," Cover the output space (at least one LOW, one MEDIUM, one HIGH) and decouple surface features from labels (a polite ticket that's HIGH, an emphatic ticket that's LOW):",[36,2178,2179],{"language":38},[40,2180,2182],{"className":42,"code":2181,"language":38,"meta":44,"style":44},"Classify the urgency of the ticket as LOW, MEDIUM, or HIGH.\nConsider business impact and blocking scope, not tone or punctuation.\n\nTicket: \"URGENT — the entire dashboard is down for our whole team, please help ASAP\"\nUrgency: HIGH\n\nTicket: \"Not sure if this matters, but the export button downloads a file\nwith the wrong date format — not blocking us, just noticed it\"\nUrgency: LOW\n\nTicket: \"We can't process any orders right now, this is costing us revenue\"\nUrgency: MEDIUM\n\nTicket: \"Hey folks, just a heads up — the export button seems to download\na file with the wrong date format — not blocking us, just noticed it\"\nUrgency:\n",[46,2183,2184,2188,2193,2197,2201,2205,2209,2214,2219,2224,2228,2233,2238,2242,2247,2251],{"__ignoreMap":44},[49,2185,2186],{"class":51,"line":52},[49,2187,2106],{"class":55},[49,2189,2190],{"class":51,"line":59},[49,2191,2192],{"class":55},"Consider business impact and blocking scope, not tone or punctuation.\n",[49,2194,2195],{"class":51,"line":65},[49,2196,75],{"emptyLinePlaceholder":74},[49,2198,2199],{"class":51,"line":71},[49,2200,2115],{"class":55},[49,2202,2203],{"class":51,"line":78},[49,2204,2120],{"class":55},[49,2206,2207],{"class":51,"line":84},[49,2208,75],{"emptyLinePlaceholder":74},[49,2210,2211],{"class":51,"line":90},[49,2212,2213],{"class":55},"Ticket: \"Not sure if this matters, but the export button downloads a file\n",[49,2215,2216],{"class":51,"line":202},[49,2217,2218],{"class":55},"with the wrong date format — not blocking us, just noticed it\"\n",[49,2220,2221],{"class":51,"line":272},[49,2222,2223],{"class":55},"Urgency: LOW\n",[49,2225,2226],{"class":51,"line":278},[49,2227,75],{"emptyLinePlaceholder":74},[49,2229,2230],{"class":51,"line":283},[49,2231,2232],{"class":55},"Ticket: \"We can't process any orders right now, this is costing us revenue\"\n",[49,2234,2235],{"class":51,"line":289},[49,2236,2237],{"class":55},"Urgency: MEDIUM\n",[49,2239,2240],{"class":51,"line":295},[49,2241,75],{"emptyLinePlaceholder":74},[49,2243,2244],{"class":51,"line":300},[49,2245,2246],{"class":55},"Ticket: \"Hey folks, just a heads up — the export button seems to download\n",[49,2248,2249],{"class":51,"line":305},[49,2250,2160],{"class":55},[49,2252,2253],{"class":51,"line":310},[49,2254,2165],{"class":55},[14,2256,2257],{},"Now the model sees: HIGH can be emphatic, LOW can be polite, MEDIUM is about revenue impact. The real input (polite, non-blocking) maps clearly to LOW because the examples decoupled tone from urgency.",[23,2259,2261],{"id":2260},"production-few-shot-email-extraction-with-varied-examples","Production Few-Shot: Email Extraction with Varied Examples",[14,2263,2264],{},"A complete, production-grade few-shot prompt for extracting structured data from customer emails — varied across name position, tone, length, issue type, and includes an out-of-scope example:",[36,2266,2267],{"language":38},[40,2268,2270],{"className":42,"code":2269,"language":38,"meta":44,"style":44},"Extract the customer's name and issue from the email.\nRespond as JSON: {\"name\": \"...\", \"issue\": \"...\"}\nIf no name is present, use null. If the email is not a support request, respond: {\"name\": null, \"issue\": null}\n\nEmail: \"Hi, this is John Carter, my order #1234 hasn't arrived.\"\nOutput: {\"name\": \"John Carter\", \"issue\": \"order #1234 not arrived\"}\n\nEmail: \"So I've been a customer for 3 years and never had this problem —\nthe app crashes every time I try to upload a photo. Frustrated, Alex Kim\"\nOutput: {\"name\": \"Alex Kim\", \"issue\": \"app crashes on photo upload\"}\n\nEmail: \"Just wanted to say thanks for the quick refund! — Sam Patel\"\nOutput: {\"name\": null, \"issue\": null}\n\nEmail: \"This is Maria Lopez from Acme Corp. Invoice 4421 has the wrong\nbilling address — we need it corrected before our monthly close.\"\nOutput: {\"name\": \"Maria Lopez\", \"issue\": \"invoice 4421 wrong billing address\"}\n\nEmail: \"login is broken. — yuki\"\nOutput: {\"name\": \"yuki\", \"issue\": \"login broken\"}\n\nEmail: \"Hey team, quick question — is there a way to export our team's\nusage data to CSV? Not urgent, just exploring. Thanks!\"\nOutput:\n",[46,2271,2272,2276,2280,2285,2289,2294,2299,2303,2307,2312,2317,2321,2326,2331,2335,2340,2345,2350,2354,2359,2364,2368,2373,2378],{"__ignoreMap":44},[49,2273,2274],{"class":51,"line":52},[49,2275,579],{"class":55},[49,2277,2278],{"class":51,"line":59},[49,2279,584],{"class":55},[49,2281,2282],{"class":51,"line":65},[49,2283,2284],{"class":55},"If no name is present, use null. If the email is not a support request, respond: {\"name\": null, \"issue\": null}\n",[49,2286,2287],{"class":51,"line":71},[49,2288,75],{"emptyLinePlaceholder":74},[49,2290,2291],{"class":51,"line":78},[49,2292,2293],{"class":55},"Email: \"Hi, this is John Carter, my order #1234 hasn't arrived.\"\n",[49,2295,2296],{"class":51,"line":84},[49,2297,2298],{"class":55},"Output: {\"name\": \"John Carter\", \"issue\": \"order #1234 not arrived\"}\n",[49,2300,2301],{"class":51,"line":90},[49,2302,75],{"emptyLinePlaceholder":74},[49,2304,2305],{"class":51,"line":202},[49,2306,635],{"class":55},[49,2308,2309],{"class":51,"line":272},[49,2310,2311],{"class":55},"the app crashes every time I try to upload a photo. Frustrated, Alex Kim\"\n",[49,2313,2314],{"class":51,"line":278},[49,2315,2316],{"class":55},"Output: {\"name\": \"Alex Kim\", \"issue\": \"app crashes on photo upload\"}\n",[49,2318,2319],{"class":51,"line":283},[49,2320,75],{"emptyLinePlaceholder":74},[49,2322,2323],{"class":51,"line":289},[49,2324,2325],{"class":55},"Email: \"Just wanted to say thanks for the quick refund! — Sam Patel\"\n",[49,2327,2328],{"class":51,"line":295},[49,2329,2330],{"class":55},"Output: {\"name\": null, \"issue\": null}\n",[49,2332,2333],{"class":51,"line":300},[49,2334,75],{"emptyLinePlaceholder":74},[49,2336,2337],{"class":51,"line":305},[49,2338,2339],{"class":55},"Email: \"This is Maria Lopez from Acme Corp. Invoice 4421 has the wrong\n",[49,2341,2342],{"class":51,"line":310},[49,2343,2344],{"class":55},"billing address — we need it corrected before our monthly close.\"\n",[49,2346,2347],{"class":51,"line":925},[49,2348,2349],{"class":55},"Output: {\"name\": \"Maria Lopez\", \"issue\": \"invoice 4421 wrong billing address\"}\n",[49,2351,2352],{"class":51,"line":954},[49,2353,75],{"emptyLinePlaceholder":74},[49,2355,2356],{"class":51,"line":982},[49,2357,2358],{"class":55},"Email: \"login is broken. — yuki\"\n",[49,2360,2361],{"class":51,"line":988},[49,2362,2363],{"class":55},"Output: {\"name\": \"yuki\", \"issue\": \"login broken\"}\n",[49,2365,2366],{"class":51,"line":993},[49,2367,75],{"emptyLinePlaceholder":74},[49,2369,2370],{"class":51,"line":1016},[49,2371,2372],{"class":55},"Email: \"Hey team, quick question — is there a way to export our team's\n",[49,2374,2375],{"class":51,"line":1022},[49,2376,2377],{"class":55},"usage data to CSV? Not urgent, just exploring. Thanks!\"\n",[49,2379,2380],{"class":51,"line":1028},[49,2381,650],{"class":55},[14,2383,2384],{},"Variation coverage in this set:",[2386,2387,2388,2395,2401,2407,2413],"ul",{},[2389,2390,2391,2394],"li",{},[31,2392,2393],{},"Name position",": start (John, Maria), end (Alex, Yuki), absent (Sam's thank-you, the CSV question)",[2389,2396,2397,2400],{},[31,2398,2399],{},"Tone",": polite (John), frustrated (Alex), formal (Maria), terse (Yuki), casual (CSV question)",[2389,2402,2403,2406],{},[31,2404,2405],{},"Length",": short (Yuki), medium (John), long (Alex, Maria)",[2389,2408,2409,2412],{},[31,2410,2411],{},"Issue type",": delivery (John), bug (Alex), billing (Maria), auth (Yuki)",[2389,2414,2415,2418,2419,2422],{},[31,2416,2417],{},"Out-of-scope",": thank-you (Sam) and feature request (CSV question) → both return ",[46,2420,2421],{},"null",", teaching the model to reject non-support emails rather than force-fitting",[23,2424,2426],{"id":2425},"tips-tricks","💡 Tips & Tricks",[36,2428,2429],{"language":698},[40,2430,2432],{"className":701,"code":2431,"language":698,"meta":44,"style":44},"# **Debug**: Log the exact prompt (system + examples + input) for EVERY request.\n# When output is wrong, you can't fix what you can't reproduce.\nimport json, hashlib\n\ndef log_prompt(system: str, examples: list, user_input: str, output: str) -> str:\n    \"\"\"Hash-stable prompt log for debugging few-shot failures.\"\"\"\n    entry = {\n        \"system\": system,\n        \"examples\": [e.output for e in examples],   # just the outputs for compactness\n        \"example_order\": [e.label for e in examples], # track WHICH examples + order\n        \"input\": user_input,\n        \"output\": output,\n        \"prompt_hash\": hashlib.sha256(\n            (system + str(examples) + user_input).encode()\n        ).hexdigest()[:12],\n    }\n    # In production: write to structured log (JSONL), queryable by prompt_hash\n    return json.dumps(entry, indent=2)\n",[46,2433,2434,2439,2444,2451,2455,2489,2494,2504,2512,2532,2552,2560,2568,2576,2594,2605,2610,2615],{"__ignoreMap":44},[49,2435,2436],{"class":51,"line":52},[49,2437,2438],{"class":773},"# **Debug**: Log the exact prompt (system + examples + input) for EVERY request.\n",[49,2440,2441],{"class":51,"line":59},[49,2442,2443],{"class":773},"# When output is wrong, you can't fix what you can't reproduce.\n",[49,2445,2446,2448],{"class":51,"line":65},[49,2447,710],{"class":709},[49,2449,2450],{"class":55}," json, hashlib\n",[49,2452,2453],{"class":51,"line":71},[49,2454,75],{"emptyLinePlaceholder":74},[49,2456,2457,2459,2462,2465,2467,2470,2472,2475,2477,2480,2482,2485,2487],{"class":51,"line":78},[49,2458,996],{"class":709},[49,2460,2461],{"class":735}," log_prompt",[49,2463,2464],{"class":55},"(system: ",[49,2466,770],{"class":124},[49,2468,2469],{"class":55},", examples: ",[49,2471,782],{"class":124},[49,2473,2474],{"class":55},", user_input: ",[49,2476,770],{"class":124},[49,2478,2479],{"class":55},", output: ",[49,2481,770],{"class":124},[49,2483,2484],{"class":55},") -> ",[49,2486,770],{"class":124},[49,2488,747],{"class":55},[49,2490,2491],{"class":51,"line":84},[49,2492,2493],{"class":131},"    \"\"\"Hash-stable prompt log for debugging few-shot failures.\"\"\"\n",[49,2495,2496,2499,2501],{"class":51,"line":90},[49,2497,2498],{"class":55},"    entry ",[49,2500,1040],{"class":709},[49,2502,2503],{"class":55}," {\n",[49,2505,2506,2509],{"class":51,"line":202},[49,2507,2508],{"class":131},"        \"system\"",[49,2510,2511],{"class":55},": system,\n",[49,2513,2514,2517,2520,2522,2524,2526,2529],{"class":51,"line":272},[49,2515,2516],{"class":131},"        \"examples\"",[49,2518,2519],{"class":55},": [e.output ",[49,2521,1151],{"class":709},[49,2523,1154],{"class":55},[49,2525,1092],{"class":709},[49,2527,2528],{"class":55}," examples],   ",[49,2530,2531],{"class":773},"# just the outputs for compactness\n",[49,2533,2534,2537,2540,2542,2544,2546,2549],{"class":51,"line":278},[49,2535,2536],{"class":131},"        \"example_order\"",[49,2538,2539],{"class":55},": [e.label ",[49,2541,1151],{"class":709},[49,2543,1154],{"class":55},[49,2545,1092],{"class":709},[49,2547,2548],{"class":55}," examples], ",[49,2550,2551],{"class":773},"# track WHICH examples + order\n",[49,2553,2554,2557],{"class":51,"line":283},[49,2555,2556],{"class":131},"        \"input\"",[49,2558,2559],{"class":55},": user_input,\n",[49,2561,2562,2565],{"class":51,"line":289},[49,2563,2564],{"class":131},"        \"output\"",[49,2566,2567],{"class":55},": output,\n",[49,2569,2570,2573],{"class":51,"line":295},[49,2571,2572],{"class":131},"        \"prompt_hash\"",[49,2574,2575],{"class":55},": hashlib.sha256(\n",[49,2577,2578,2581,2583,2586,2589,2591],{"class":51,"line":300},[49,2579,2580],{"class":55},"            (system ",[49,2582,1440],{"class":709},[49,2584,2585],{"class":124}," str",[49,2587,2588],{"class":55},"(examples) ",[49,2590,1440],{"class":709},[49,2592,2593],{"class":55}," user_input).encode()\n",[49,2595,2596,2599,2602],{"class":51,"line":305},[49,2597,2598],{"class":55},"        ).hexdigest()[:",[49,2600,2601],{"class":124},"12",[49,2603,2604],{"class":55},"],\n",[49,2606,2607],{"class":51,"line":310},[49,2608,2609],{"class":55},"    }\n",[49,2611,2612],{"class":51,"line":925},[49,2613,2614],{"class":773},"    # In production: write to structured log (JSONL), queryable by prompt_hash\n",[49,2616,2617,2619,2622,2625,2627,2630],{"class":51,"line":954},[49,2618,1273],{"class":709},[49,2620,2621],{"class":55}," json.dumps(entry, ",[49,2623,2624],{"class":1204},"indent",[49,2626,1040],{"class":709},[49,2628,2629],{"class":124},"2",[49,2631,1239],{"class":55},[36,2633,2634],{"language":698},[40,2635,2637],{"className":701,"code":2636,"language":698,"meta":44,"style":44},"# **Cost**: Few-shot examples cost tokens on EVERY request — they scale with volume.\n# A system prompt improvement is a one-time cost. Always tighten instructions first.\n# \n# Example: 5 examples × 120 tokens = 600 tokens\u002Frequest.\n# At 10K requests\u002Fday: 6M tokens\u002Fday spent on examples alone.\n# If a tighter zero-shot instruction achieves the same accuracy: 0 tokens\u002Fday on examples.\n#\n# Measure: log (prompt_tokens, completion_tokens) per request, aggregate by task type.\n# If example tokens > 40% of prompt_tokens, audit whether examples are earning their cost.\n",[46,2638,2639,2644,2649,2654,2659,2664,2669,2674,2679],{"__ignoreMap":44},[49,2640,2641],{"class":51,"line":52},[49,2642,2643],{"class":773},"# **Cost**: Few-shot examples cost tokens on EVERY request — they scale with volume.\n",[49,2645,2646],{"class":51,"line":59},[49,2647,2648],{"class":773},"# A system prompt improvement is a one-time cost. Always tighten instructions first.\n",[49,2650,2651],{"class":51,"line":65},[49,2652,2653],{"class":773},"# \n",[49,2655,2656],{"class":51,"line":71},[49,2657,2658],{"class":773},"# Example: 5 examples × 120 tokens = 600 tokens\u002Frequest.\n",[49,2660,2661],{"class":51,"line":78},[49,2662,2663],{"class":773},"# At 10K requests\u002Fday: 6M tokens\u002Fday spent on examples alone.\n",[49,2665,2666],{"class":51,"line":84},[49,2667,2668],{"class":773},"# If a tighter zero-shot instruction achieves the same accuracy: 0 tokens\u002Fday on examples.\n",[49,2670,2671],{"class":51,"line":90},[49,2672,2673],{"class":773},"#\n",[49,2675,2676],{"class":51,"line":202},[49,2677,2678],{"class":773},"# Measure: log (prompt_tokens, completion_tokens) per request, aggregate by task type.\n",[49,2680,2681],{"class":51,"line":272},[49,2682,2683],{"class":773},"# If example tokens > 40% of prompt_tokens, audit whether examples are earning their cost.\n",[36,2685,2686],{"language":698},[40,2687,2689],{"className":701,"code":2688,"language":698,"meta":44,"style":44},"# **Idiom**: Start at zero-shot. ALWAYS. Even if you're \"sure\" you need few-shot.\n# Write the zero-shot version, test on 50+ real inputs, measure failure rate.\n# Only add examples for SPECIFIC observed failures — not hypothetical ones.\n# This is the single highest-leverage discipline in prompt engineering.\n\nZERO_SHOT_SYSTEM = (\n    \"Extract the customer's name and issue from the email. \"\n    'Respond as JSON: {\"name\": \"...\", \"issue\": \"...\"}. '\n    \"If no name is present, use null. \"\n    \"If the email is not a support request, respond: \"\n    '{\"name\": null, \"issue\": null}'\n)\n# Test this FIRST. If accuracy > 95% on your eval set, you're done. No examples needed.\n",[46,2690,2691,2696,2701,2706,2711,2715,2725,2730,2735,2740,2745,2750,2754],{"__ignoreMap":44},[49,2692,2693],{"class":51,"line":52},[49,2694,2695],{"class":773},"# **Idiom**: Start at zero-shot. ALWAYS. Even if you're \"sure\" you need few-shot.\n",[49,2697,2698],{"class":51,"line":59},[49,2699,2700],{"class":773},"# Write the zero-shot version, test on 50+ real inputs, measure failure rate.\n",[49,2702,2703],{"class":51,"line":65},[49,2704,2705],{"class":773},"# Only add examples for SPECIFIC observed failures — not hypothetical ones.\n",[49,2707,2708],{"class":51,"line":71},[49,2709,2710],{"class":773},"# This is the single highest-leverage discipline in prompt engineering.\n",[49,2712,2713],{"class":51,"line":78},[49,2714,75],{"emptyLinePlaceholder":74},[49,2716,2717,2720,2722],{"class":51,"line":84},[49,2718,2719],{"class":124},"ZERO_SHOT_SYSTEM",[49,2721,802],{"class":709},[49,2723,2724],{"class":55}," (\n",[49,2726,2727],{"class":51,"line":90},[49,2728,2729],{"class":131},"    \"Extract the customer's name and issue from the email. \"\n",[49,2731,2732],{"class":51,"line":202},[49,2733,2734],{"class":131},"    'Respond as JSON: {\"name\": \"...\", \"issue\": \"...\"}. '\n",[49,2736,2737],{"class":51,"line":272},[49,2738,2739],{"class":131},"    \"If no name is present, use null. \"\n",[49,2741,2742],{"class":51,"line":278},[49,2743,2744],{"class":131},"    \"If the email is not a support request, respond: \"\n",[49,2746,2747],{"class":51,"line":283},[49,2748,2749],{"class":131},"    '{\"name\": null, \"issue\": null}'\n",[49,2751,2752],{"class":51,"line":289},[49,2753,1239],{"class":55},[49,2755,2756],{"class":51,"line":295},[49,2757,2758],{"class":773},"# Test this FIRST. If accuracy > 95% on your eval set, you're done. No examples needed.\n",[36,2760,2761],{"language":698},[40,2762,2764],{"className":701,"code":2763,"language":698,"meta":44,"style":44},"# **Maintenance**: Stale examples silently rot. If your product adds a new category\n# or edge case and your few-shot set doesn't reflect it, the prompt steers the model\n# toward outdated behavior. Version your prompt + example set together.\n# \n# Production pattern: store examples in a versioned config, not hardcoded in the prompt:\nEXAMPLE_SET_VERSION = \"2026-09-10-v3\"  # bump when examples change\n# Log this with every request → when accuracy drops, you can correlate to a version change.\n",[46,2765,2766,2771,2776,2781,2785,2790,2803],{"__ignoreMap":44},[49,2767,2768],{"class":51,"line":52},[49,2769,2770],{"class":773},"# **Maintenance**: Stale examples silently rot. If your product adds a new category\n",[49,2772,2773],{"class":51,"line":59},[49,2774,2775],{"class":773},"# or edge case and your few-shot set doesn't reflect it, the prompt steers the model\n",[49,2777,2778],{"class":51,"line":65},[49,2779,2780],{"class":773},"# toward outdated behavior. Version your prompt + example set together.\n",[49,2782,2783],{"class":51,"line":71},[49,2784,2653],{"class":773},[49,2786,2787],{"class":51,"line":78},[49,2788,2789],{"class":773},"# Production pattern: store examples in a versioned config, not hardcoded in the prompt:\n",[49,2791,2792,2795,2797,2800],{"class":51,"line":84},[49,2793,2794],{"class":124},"EXAMPLE_SET_VERSION",[49,2796,802],{"class":709},[49,2798,2799],{"class":131}," \"2026-09-10-v3\"",[49,2801,2802],{"class":773},"  # bump when examples change\n",[49,2804,2805],{"class":51,"line":90},[49,2806,2807],{"class":773},"# Log this with every request → when accuracy drops, you can correlate to a version change.\n",[23,2809,2811],{"id":2810},"️-edge-cases-gotchas","⚠️ Edge Cases & Gotchas",[36,2813,2814],{"language":698},[40,2815,2817],{"className":701,"code":2816,"language":698,"meta":44,"style":44},"# **Safety**: A single example can be worse than zero examples.\n# With N=1, the model can't distinguish \"general rule\" from \"incidental detail.\"\n# Every surface feature of that one example (tone, length, phrasing) is\n# indistinguishable from the task pattern.\n# \n# If you can only afford one example: make it maximally representative (average\n# length, neutral tone, common case) — or skip it and use a clearer zero-shot\n# instruction instead. N=1 is the most dangerous few-shot configuration.\n",[46,2818,2819,2824,2829,2834,2839,2843,2848,2853],{"__ignoreMap":44},[49,2820,2821],{"class":51,"line":52},[49,2822,2823],{"class":773},"# **Safety**: A single example can be worse than zero examples.\n",[49,2825,2826],{"class":51,"line":59},[49,2827,2828],{"class":773},"# With N=1, the model can't distinguish \"general rule\" from \"incidental detail.\"\n",[49,2830,2831],{"class":51,"line":65},[49,2832,2833],{"class":773},"# Every surface feature of that one example (tone, length, phrasing) is\n",[49,2835,2836],{"class":51,"line":71},[49,2837,2838],{"class":773},"# indistinguishable from the task pattern.\n",[49,2840,2841],{"class":51,"line":78},[49,2842,2653],{"class":773},[49,2844,2845],{"class":51,"line":84},[49,2846,2847],{"class":773},"# If you can only afford one example: make it maximally representative (average\n",[49,2849,2850],{"class":51,"line":90},[49,2851,2852],{"class":773},"# length, neutral tone, common case) — or skip it and use a clearer zero-shot\n",[49,2854,2855],{"class":51,"line":202},[49,2856,2857],{"class":773},"# instruction instead. N=1 is the most dangerous few-shot configuration.\n",[36,2859,2860],{"language":698},[40,2861,2863],{"className":701,"code":2862,"language":698,"meta":44,"style":44},"# **Safety**: Few-shot doesn't reliably teach counting or exact quantities.\n# Showing 3 examples of \"extract the top 2 keywords\" doesn't teach \"always exactly 2.\"\n# The model extracts \"produce a short list\" not \"produce the integer 2.\"\n# \n# Fix: state the number explicitly in the instruction, don't rely on examples to imply it.\nINSTRUCTION = \"Extract exactly 2 keywords from the text. Respond as a JSON array of exactly 2 strings.\"\n# The examples reinforce format; the instruction enforces the count.\n",[46,2864,2865,2870,2875,2880,2884,2889,2899],{"__ignoreMap":44},[49,2866,2867],{"class":51,"line":52},[49,2868,2869],{"class":773},"# **Safety**: Few-shot doesn't reliably teach counting or exact quantities.\n",[49,2871,2872],{"class":51,"line":59},[49,2873,2874],{"class":773},"# Showing 3 examples of \"extract the top 2 keywords\" doesn't teach \"always exactly 2.\"\n",[49,2876,2877],{"class":51,"line":65},[49,2878,2879],{"class":773},"# The model extracts \"produce a short list\" not \"produce the integer 2.\"\n",[49,2881,2882],{"class":51,"line":71},[49,2883,2653],{"class":773},[49,2885,2886],{"class":51,"line":78},[49,2887,2888],{"class":773},"# Fix: state the number explicitly in the instruction, don't rely on examples to imply it.\n",[49,2890,2891,2894,2896],{"class":51,"line":84},[49,2892,2893],{"class":124},"INSTRUCTION",[49,2895,802],{"class":709},[49,2897,2898],{"class":131}," \"Extract exactly 2 keywords from the text. Respond as a JSON array of exactly 2 strings.\"\n",[49,2900,2901],{"class":51,"line":90},[49,2902,2903],{"class":773},"# The examples reinforce format; the instruction enforces the count.\n",[36,2905,2906],{"language":698},[40,2907,2909],{"className":701,"code":2908,"language":698,"meta":44,"style":44},"# **Portability**: Fake assistant-turn examples must not contain meta-text.\n# If you copy-pasted a real model response as your example, it may contain\n# conversational wrappers: \"Sure, here's the answer:\" or \"Let me classify that for you:\"\n# The model learns to reproduce the WRAPPER as part of the desired output.\n# \n# BAD assistant turn:\n#   {\"role\": \"assistant\", \"content\": \"Sure! Here's the classification: POSITIVE\"}\n# GOOD assistant turn:\n#   {\"role\": \"assistant\", \"content\": \"POSITIVE\"}\n# \n# Always strip artifacts of HOW you produced the example. The assistant turn\n# should contain ONLY the desired output, nothing else.\n",[46,2910,2911,2916,2921,2926,2931,2935,2940,2945,2950,2955,2959,2964],{"__ignoreMap":44},[49,2912,2913],{"class":51,"line":52},[49,2914,2915],{"class":773},"# **Portability**: Fake assistant-turn examples must not contain meta-text.\n",[49,2917,2918],{"class":51,"line":59},[49,2919,2920],{"class":773},"# If you copy-pasted a real model response as your example, it may contain\n",[49,2922,2923],{"class":51,"line":65},[49,2924,2925],{"class":773},"# conversational wrappers: \"Sure, here's the answer:\" or \"Let me classify that for you:\"\n",[49,2927,2928],{"class":51,"line":71},[49,2929,2930],{"class":773},"# The model learns to reproduce the WRAPPER as part of the desired output.\n",[49,2932,2933],{"class":51,"line":78},[49,2934,2653],{"class":773},[49,2936,2937],{"class":51,"line":84},[49,2938,2939],{"class":773},"# BAD assistant turn:\n",[49,2941,2942],{"class":51,"line":90},[49,2943,2944],{"class":773},"#   {\"role\": \"assistant\", \"content\": \"Sure! Here's the classification: POSITIVE\"}\n",[49,2946,2947],{"class":51,"line":202},[49,2948,2949],{"class":773},"# GOOD assistant turn:\n",[49,2951,2952],{"class":51,"line":272},[49,2953,2954],{"class":773},"#   {\"role\": \"assistant\", \"content\": \"POSITIVE\"}\n",[49,2956,2957],{"class":51,"line":278},[49,2958,2653],{"class":773},[49,2960,2961],{"class":51,"line":283},[49,2962,2963],{"class":773},"# Always strip artifacts of HOW you produced the example. The assistant turn\n",[49,2965,2966],{"class":51,"line":289},[49,2967,2968],{"class":773},"# should contain ONLY the desired output, nothing else.\n",[36,2970,2971],{"language":698},[40,2972,2974],{"className":701,"code":2973,"language":698,"meta":44,"style":44},"# **Portability**: Very long individual examples dominate attention by length,\n# not by relevance. If one example includes a lengthy input document, it consumes\n# a disproportionate fraction of the prompt's effective attention budget.\n# \n# Rule of thumb: keep example input lengths within 2x of each other.\n# If you need a long-document example, consider retrieval (RAG) instead of in-context few-shot.\n",[46,2975,2976,2981,2986,2991,2995,3000],{"__ignoreMap":44},[49,2977,2978],{"class":51,"line":52},[49,2979,2980],{"class":773},"# **Portability**: Very long individual examples dominate attention by length,\n",[49,2982,2983],{"class":51,"line":59},[49,2984,2985],{"class":773},"# not by relevance. If one example includes a lengthy input document, it consumes\n",[49,2987,2988],{"class":51,"line":65},[49,2989,2990],{"class":773},"# a disproportionate fraction of the prompt's effective attention budget.\n",[49,2992,2993],{"class":51,"line":71},[49,2994,2653],{"class":773},[49,2996,2997],{"class":51,"line":78},[49,2998,2999],{"class":773},"# Rule of thumb: keep example input lengths within 2x of each other.\n",[49,3001,3002],{"class":51,"line":84},[49,3003,3004],{"class":773},"# If you need a long-document example, consider retrieval (RAG) instead of in-context few-shot.\n",[36,3006,3007],{"language":698},[40,3008,3010],{"className":701,"code":3009,"language":698,"meta":44,"style":44},"# **Safety**: Few-shot examples that are all correct hide boundary behavior.\n# If none of your examples show what an INVALID or out-of-scope input produces,\n# the model has no guidance for rejecting non-matching inputs — it force-fits\n# to the closest category instead of flagging the mismatch.\n# \n# Fix: include at least one out-of-scope example that demonstrates rejection:\n#   Email: \"Thanks for the great service!\" -> Output: {\"name\": null, \"issue\": null}\n# This teaches: \"not every input is a valid input — return null when it doesn't fit.\"\n",[46,3011,3012,3017,3022,3027,3032,3036,3041,3046],{"__ignoreMap":44},[49,3013,3014],{"class":51,"line":52},[49,3015,3016],{"class":773},"# **Safety**: Few-shot examples that are all correct hide boundary behavior.\n",[49,3018,3019],{"class":51,"line":59},[49,3020,3021],{"class":773},"# If none of your examples show what an INVALID or out-of-scope input produces,\n",[49,3023,3024],{"class":51,"line":65},[49,3025,3026],{"class":773},"# the model has no guidance for rejecting non-matching inputs — it force-fits\n",[49,3028,3029],{"class":51,"line":71},[49,3030,3031],{"class":773},"# to the closest category instead of flagging the mismatch.\n",[49,3033,3034],{"class":51,"line":78},[49,3035,2653],{"class":773},[49,3037,3038],{"class":51,"line":84},[49,3039,3040],{"class":773},"# Fix: include at least one out-of-scope example that demonstrates rejection:\n",[49,3042,3043],{"class":51,"line":90},[49,3044,3045],{"class":773},"#   Email: \"Thanks for the great service!\" -> Output: {\"name\": null, \"issue\": null}\n",[49,3047,3048],{"class":51,"line":202},[49,3049,3050],{"class":773},"# This teaches: \"not every input is a valid input — return null when it doesn't fit.\"\n",[23,3052,3054],{"id":3053},"spot-the-bug","🧠 Spot the Bug",[14,3056,3057],{},"A team builds this few-shot prompt for ticket classification:",[36,3059,3060],{"language":38},[40,3061,3062],{"className":42,"code":2099,"language":38,"meta":44,"style":44},[46,3063,3064,3068,3072,3076,3080,3084,3088,3092,3096,3100,3104,3108,3112,3116],{"__ignoreMap":44},[49,3065,3066],{"class":51,"line":52},[49,3067,2106],{"class":55},[49,3069,3070],{"class":51,"line":59},[49,3071,75],{"emptyLinePlaceholder":74},[49,3073,3074],{"class":51,"line":65},[49,3075,2115],{"class":55},[49,3077,3078],{"class":51,"line":71},[49,3079,2120],{"class":55},[49,3081,3082],{"class":51,"line":78},[49,3083,75],{"emptyLinePlaceholder":74},[49,3085,3086],{"class":51,"line":84},[49,3087,2129],{"class":55},[49,3089,3090],{"class":51,"line":90},[49,3091,2120],{"class":55},[49,3093,3094],{"class":51,"line":202},[49,3095,75],{"emptyLinePlaceholder":74},[49,3097,3098],{"class":51,"line":272},[49,3099,2142],{"class":55},[49,3101,3102],{"class":51,"line":278},[49,3103,2120],{"class":55},[49,3105,3106],{"class":51,"line":283},[49,3107,75],{"emptyLinePlaceholder":74},[49,3109,3110],{"class":51,"line":289},[49,3111,2155],{"class":55},[49,3113,3114],{"class":51,"line":295},[49,3115,2160],{"class":55},[49,3117,3118],{"class":51,"line":300},[49,3119,2165],{"class":55},[14,3121,3122],{},"In production, the model reliably classifies clearly low-urgency tickets as MEDIUM or HIGH — especially if the ticket text includes emphatic punctuation or the word \"please.\" What went wrong?",[3124,3125,3126,3130,3133,3160],"details",{},[3127,3128,3129],"summary",{},"Answer",[14,3131,3132],{},"Two compounding problems:",[3134,3135,3136,3142],"ol",{},[2389,3137,3138,3141],{},[31,3139,3140],{},"Zero label diversity."," All three examples are HIGH. The model has never seen what LOW or MEDIUM looks like — it can only infer urgency by pattern-matching lexical surface features (\"urgent,\" exclamation marks, emphatic tone) that co-occurred with HIGH in this sample. It learned \"emphatic = HIGH\" because tone and impact were perfectly correlated in every example.",[2389,3143,3144,3147,3148,3151,3152,3155,3156,3159],{},[31,3145,3146],{},"Incidental surface correlation."," All examples came from a single outage event, so they share emphatic tone, exclamation marks, and vocabulary — none of which is the ",[18,3149,3150],{},"real"," classification signal (business impact, blocking scope). The model has no way to learn that urgency is about ",[18,3153,3154],{},"impact",", not ",[18,3157,3158],{},"tone",", because tone and impact were identical in every example.",[14,3161,3162,3165],{},[31,3163,3164],{},"Fix:"," Include at least one LOW and one MEDIUM example. Decouple surface features from labels — a polite ticket that's HIGH, an emphatic ticket that's LOW. The real ticket (polite, non-blocking, minor) should map unambiguously to LOW because the examples teach \"impact matters, tone doesn't.\"",[23,3167,3169],{"id":3168},"key-takeaways","Key Takeaways",[36,3171,3172],{"language":698},[40,3173,3175],{"className":701,"code":3174,"language":698,"meta":44,"style":44},"# Zero-shot is the default. Always test here first.\n# Few-shot earns its cost only when: format is hard to describe, edge cases need\n# pinning, or zero-shot output is inconsistent across similar inputs.\n#\n# The diminishing-returns curve: 0->2 examples is the steep jump. Past ~5 diverse\n# examples, spend effort on WHICH examples, not HOW MANY.\n#\n# Example selection > example count:\n#   - Cover the output space (at least one of each label)\n#   - Vary irrelevant surface features (tone, length, position) so the model\n#     can't latch onto spurious correlations\n#   - Include out-of-scope examples to teach rejection, not just classification\n#\n# Example ordering matters:\n#   - The last example (closest to real input) has outsized influence (recency)\n#   - Place your hardest\u002Fmost representative example last\n#   - Shuffle to avoid positional patterns the model could exploit\n#\n# Cost discipline:\n#   - Examples scale with volume (tokens per request x request count)\n#   - Tighten instructions first; add examples only when instruction-tuning plateaus\n#   - Version your example set; stale examples silently rot and steer toward\n#     outdated behavior\n#\n# The accidental-pattern trap:\n#   - Homogeneous examples teach a NARROWER rule than the task requires\n#   - N=1 is the most dangerous configuration (can't separate signal from noise)\n#   - A bad few-shot set can perform WORSE than zero-shot — always benchmark both\n",[46,3176,3177,3182,3187,3192,3196,3201,3206,3210,3215,3220,3225,3230,3235,3239,3244,3249,3254,3259,3263,3268,3273,3278,3283,3288,3292,3297,3302,3307],{"__ignoreMap":44},[49,3178,3179],{"class":51,"line":52},[49,3180,3181],{"class":773},"# Zero-shot is the default. Always test here first.\n",[49,3183,3184],{"class":51,"line":59},[49,3185,3186],{"class":773},"# Few-shot earns its cost only when: format is hard to describe, edge cases need\n",[49,3188,3189],{"class":51,"line":65},[49,3190,3191],{"class":773},"# pinning, or zero-shot output is inconsistent across similar inputs.\n",[49,3193,3194],{"class":51,"line":71},[49,3195,2673],{"class":773},[49,3197,3198],{"class":51,"line":78},[49,3199,3200],{"class":773},"# The diminishing-returns curve: 0->2 examples is the steep jump. Past ~5 diverse\n",[49,3202,3203],{"class":51,"line":84},[49,3204,3205],{"class":773},"# examples, spend effort on WHICH examples, not HOW MANY.\n",[49,3207,3208],{"class":51,"line":90},[49,3209,2673],{"class":773},[49,3211,3212],{"class":51,"line":202},[49,3213,3214],{"class":773},"# Example selection > example count:\n",[49,3216,3217],{"class":51,"line":272},[49,3218,3219],{"class":773},"#   - Cover the output space (at least one of each label)\n",[49,3221,3222],{"class":51,"line":278},[49,3223,3224],{"class":773},"#   - Vary irrelevant surface features (tone, length, position) so the model\n",[49,3226,3227],{"class":51,"line":283},[49,3228,3229],{"class":773},"#     can't latch onto spurious correlations\n",[49,3231,3232],{"class":51,"line":289},[49,3233,3234],{"class":773},"#   - Include out-of-scope examples to teach rejection, not just classification\n",[49,3236,3237],{"class":51,"line":295},[49,3238,2673],{"class":773},[49,3240,3241],{"class":51,"line":300},[49,3242,3243],{"class":773},"# Example ordering matters:\n",[49,3245,3246],{"class":51,"line":305},[49,3247,3248],{"class":773},"#   - The last example (closest to real input) has outsized influence (recency)\n",[49,3250,3251],{"class":51,"line":310},[49,3252,3253],{"class":773},"#   - Place your hardest\u002Fmost representative example last\n",[49,3255,3256],{"class":51,"line":925},[49,3257,3258],{"class":773},"#   - Shuffle to avoid positional patterns the model could exploit\n",[49,3260,3261],{"class":51,"line":954},[49,3262,2673],{"class":773},[49,3264,3265],{"class":51,"line":982},[49,3266,3267],{"class":773},"# Cost discipline:\n",[49,3269,3270],{"class":51,"line":988},[49,3271,3272],{"class":773},"#   - Examples scale with volume (tokens per request x request count)\n",[49,3274,3275],{"class":51,"line":993},[49,3276,3277],{"class":773},"#   - Tighten instructions first; add examples only when instruction-tuning plateaus\n",[49,3279,3280],{"class":51,"line":1016},[49,3281,3282],{"class":773},"#   - Version your example set; stale examples silently rot and steer toward\n",[49,3284,3285],{"class":51,"line":1022},[49,3286,3287],{"class":773},"#     outdated behavior\n",[49,3289,3290],{"class":51,"line":1028},[49,3291,2673],{"class":773},[49,3293,3294],{"class":51,"line":1034},[49,3295,3296],{"class":773},"# The accidental-pattern trap:\n",[49,3298,3299],{"class":51,"line":1046},[49,3300,3301],{"class":773},"#   - Homogeneous examples teach a NARROWER rule than the task requires\n",[49,3303,3304],{"class":51,"line":1063},[49,3305,3306],{"class":773},"#   - N=1 is the most dangerous configuration (can't separate signal from noise)\n",[49,3308,3309],{"class":51,"line":1069},[49,3310,3311],{"class":773},"#   - A bad few-shot set can perform WORSE than zero-shot — always benchmark both\n",[3313,3314,3315],"style",{},"html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}html pre.shiki code .sCrzJ, html code.shiki .sCrzJ{--shiki-default:#E36209;--shiki-github-dark:#FFAB70}",{"title":44,"searchDepth":59,"depth":59,"links":3317},[3318,3321,3325,3328,3329,3330,3331,3332,3333,3334,3335,3336],{"id":25,"depth":59,"text":26,"children":3319},[3320],{"id":104,"depth":65,"text":105},{"id":217,"depth":59,"text":218,"children":3322},[3323,3324],{"id":224,"depth":65,"text":225},{"id":322,"depth":65,"text":323},{"id":547,"depth":59,"text":548,"children":3326},[3327],{"id":566,"depth":65,"text":567},{"id":683,"depth":59,"text":684},{"id":1531,"depth":59,"text":1532},{"id":1989,"depth":59,"text":1990},{"id":2090,"depth":59,"text":2091},{"id":2260,"depth":59,"text":2261},{"id":2425,"depth":59,"text":2426},{"id":2810,"depth":59,"text":2811},{"id":3053,"depth":59,"text":3054},{"id":3168,"depth":59,"text":3169},"Zero-shot classification, few-shot via text vs conversation structure, example selection, ordering effects, diminishing returns, and production patterns — code-first reference for mid-to-senior engineers.","md",{},"\u002Fprompt-engineering\u002F03-zero-shot-and-few-shot-prompting",{"title":5,"description":3337},"prompt-engineering\u002F03-zero-shot-and-few-shot-prompting","QItJ3hggRrRmtQmWELLz8Bl5bFWwjAwjhxMgI1ZiRXg",1789924650801]