[{"data":1,"prerenderedAt":1151},["ShallowReactive",2],{"page-\u002Fprompt-engineering\u002F06-role-and-persona-prompting":3},{"id":4,"title":5,"body":6,"description":1144,"extension":1145,"meta":1146,"navigation":58,"path":1147,"seo":1148,"stem":1149,"__hash__":1150},"content\u002Fprompt-engineering\u002F06-role-and-persona-prompting.md","06 — Role & Persona Prompting",{"type":7,"value":8,"toc":1132},"minimark",[9,13,18,230,234,279,297,310,314,414,418,464,467,510,521,525,553,561,594,598,626,654,657,661,801,805,939,943,966,969,993,997,1128],[10,11,5],"h1",{"id":12},"_06-role-persona-prompting",[14,15,17],"h2",{"id":16},"what-a-persona-mechanistically-does","What a Persona Mechanistically Does",[19,20,23],"code-wrapper",{"filename":21,"language":22},"persona_mechanism.py","python",[24,25,29],"pre",{"className":26,"code":27,"language":22,"meta":28,"style":28},"language-python shiki shiki-themes github-light github-dark","# A persona is a CONDITIONING SIGNAL, not an identity the model adopts.\n# The model has no self — it has a learned mapping from textual framings to\n# regions of its training distribution.\n\n# \"Senior security engineer\" statistically co-occurs, in training data, with\n# careful, technical, risk-focused, jargon-appropriate text.\n# \"Friendly customer support agent for a children's toy company\" co-occurs with\n# warm, simple, reassuring, brand-safe text.\n#\n# The persona is a COMPACT way of pointing at a cluster of stylistic and\n# substantive properties you'd otherwise have to enumerate individually.\n\n# WHEN IT HELPS: target behavior genuinely correlates with the persona\n#   in the real world (and therefore in training data)\n# WHEN IT'S THEATER: it doesn't — \"you are a careful accountant\" won't make\n#   the model actually double-check debits equal credits (see anti-pattern below)\n\n# PSEUDOCODE:\ndef persona_effect(persona_text: str, model_distribution: dict) -> dict:\n    \"\"\"A persona shifts the probability distribution toward the region\n    associated with that framing in training data.\"\"\"\n    region = model_distribution[persona_text]  # e.g. \"expert security engineer\" → careful, technical\n    return shift_distribution_towards(model_distribution, region)\n    # The model samples from this shifted distribution for ALL subsequent tokens.\n    # It's not \"becoming\" a security engineer — it's generating text statistically\n    # consistent with how security engineers write.\n","",[30,31,32,41,47,53,60,66,72,78,84,90,96,102,107,113,119,125,131,136,142,175,182,188,203,212,218,224],"code",{"__ignoreMap":28},[33,34,37],"span",{"class":35,"line":36},"line",1,[33,38,40],{"class":39},"sdCPZ","# A persona is a CONDITIONING SIGNAL, not an identity the model adopts.\n",[33,42,44],{"class":35,"line":43},2,[33,45,46],{"class":39},"# The model has no self — it has a learned mapping from textual framings to\n",[33,48,50],{"class":35,"line":49},3,[33,51,52],{"class":39},"# regions of its training distribution.\n",[33,54,56],{"class":35,"line":55},4,[33,57,59],{"emptyLinePlaceholder":58},true,"\n",[33,61,63],{"class":35,"line":62},5,[33,64,65],{"class":39},"# \"Senior security engineer\" statistically co-occurs, in training data, with\n",[33,67,69],{"class":35,"line":68},6,[33,70,71],{"class":39},"# careful, technical, risk-focused, jargon-appropriate text.\n",[33,73,75],{"class":35,"line":74},7,[33,76,77],{"class":39},"# \"Friendly customer support agent for a children's toy company\" co-occurs with\n",[33,79,81],{"class":35,"line":80},8,[33,82,83],{"class":39},"# warm, simple, reassuring, brand-safe text.\n",[33,85,87],{"class":35,"line":86},9,[33,88,89],{"class":39},"#\n",[33,91,93],{"class":35,"line":92},10,[33,94,95],{"class":39},"# The persona is a COMPACT way of pointing at a cluster of stylistic and\n",[33,97,99],{"class":35,"line":98},11,[33,100,101],{"class":39},"# substantive properties you'd otherwise have to enumerate individually.\n",[33,103,105],{"class":35,"line":104},12,[33,106,59],{"emptyLinePlaceholder":58},[33,108,110],{"class":35,"line":109},13,[33,111,112],{"class":39},"# WHEN IT HELPS: target behavior genuinely correlates with the persona\n",[33,114,116],{"class":35,"line":115},14,[33,117,118],{"class":39},"#   in the real world (and therefore in training data)\n",[33,120,122],{"class":35,"line":121},15,[33,123,124],{"class":39},"# WHEN IT'S THEATER: it doesn't — \"you are a careful accountant\" won't make\n",[33,126,128],{"class":35,"line":127},16,[33,129,130],{"class":39},"#   the model actually double-check debits equal credits (see anti-pattern below)\n",[33,132,134],{"class":35,"line":133},17,[33,135,59],{"emptyLinePlaceholder":58},[33,137,139],{"class":35,"line":138},18,[33,140,141],{"class":39},"# PSEUDOCODE:\n",[33,143,145,149,153,157,161,164,167,170,172],{"class":35,"line":144},19,[33,146,148],{"class":147},"svdQ7","def",[33,150,152],{"class":151},"sIsaT"," persona_effect",[33,154,156],{"class":155},"ssxIu","(persona_text: ",[33,158,160],{"class":159},"snvgF","str",[33,162,163],{"class":155},", model_distribution: ",[33,165,166],{"class":159},"dict",[33,168,169],{"class":155},") -> ",[33,171,166],{"class":159},[33,173,174],{"class":155},":\n",[33,176,178],{"class":35,"line":177},20,[33,179,181],{"class":180},"sJ6F3","    \"\"\"A persona shifts the probability distribution toward the region\n",[33,183,185],{"class":35,"line":184},21,[33,186,187],{"class":180},"    associated with that framing in training data.\"\"\"\n",[33,189,191,194,197,200],{"class":35,"line":190},22,[33,192,193],{"class":155},"    region ",[33,195,196],{"class":147},"=",[33,198,199],{"class":155}," model_distribution[persona_text]  ",[33,201,202],{"class":39},"# e.g. \"expert security engineer\" → careful, technical\n",[33,204,206,209],{"class":35,"line":205},23,[33,207,208],{"class":147},"    return",[33,210,211],{"class":155}," shift_distribution_towards(model_distribution, region)\n",[33,213,215],{"class":35,"line":214},24,[33,216,217],{"class":39},"    # The model samples from this shifted distribution for ALL subsequent tokens.\n",[33,219,221],{"class":35,"line":220},25,[33,222,223],{"class":39},"    # It's not \"becoming\" a security engineer — it's generating text statistically\n",[33,225,227],{"class":35,"line":226},26,[33,228,229],{"class":39},"    # consistent with how security engineers write.\n",[14,231,233],{"id":232},"production-persona-specific-expertise-explicit-priorities","Production Persona: Specific Expertise + Explicit Priorities",[19,235,238],{"filename":236,"language":237},"production_persona.md","markdown",[24,239,242],{"className":240,"code":241,"language":237,"meta":28,"style":28},"language-markdown shiki shiki-themes github-light github-dark","You are a senior code reviewer at a fintech company with deep expertise in\ndistributed systems and financial compliance requirements. You review pull\nrequests with an emphasis on correctness under concurrency, audit-trail\ncompleteness, and edge cases around money (rounding, currency conversion,\nidempotency of financial operations). You are direct and specific in\nfeedback — you cite the exact line and explain the failure mode, not just\n\"this could be better.\"\n",[30,243,244,249,254,259,264,269,274],{"__ignoreMap":28},[33,245,246],{"class":35,"line":36},[33,247,248],{"class":155},"You are a senior code reviewer at a fintech company with deep expertise in\n",[33,250,251],{"class":35,"line":43},[33,252,253],{"class":155},"distributed systems and financial compliance requirements. You review pull\n",[33,255,256],{"class":35,"line":49},[33,257,258],{"class":155},"requests with an emphasis on correctness under concurrency, audit-trail\n",[33,260,261],{"class":35,"line":55},[33,262,263],{"class":155},"completeness, and edge cases around money (rounding, currency conversion,\n",[33,265,266],{"class":35,"line":62},[33,267,268],{"class":155},"idempotency of financial operations). You are direct and specific in\n",[33,270,271],{"class":35,"line":68},[33,272,273],{"class":155},"feedback — you cite the exact line and explain the failure mode, not just\n",[33,275,276],{"class":35,"line":74},[33,277,278],{"class":155},"\"this could be better.\"\n",[19,280,282],{"filename":281,"language":237},"vague_persona.md",[24,283,285],{"className":240,"code":284,"language":237,"meta":28,"style":28},"\u003C!-- ANTI-PATTERN: barely narrows the distribution at all -->\nYou are a helpful code reviewer.\n",[30,286,287,292],{"__ignoreMap":28},[33,288,289],{"class":35,"line":36},[33,290,291],{"class":39},"\u003C!-- ANTI-PATTERN: barely narrows the distribution at all -->\n",[33,293,294],{"class":35,"line":43},[33,295,296],{"class":155},"You are a helpful code reviewer.\n",[298,299,300,301,305,306,309],"p",{},"The specific persona names the ",[302,303,304],"em",{},"expertise domain"," (fintech, distributed systems, compliance) and the ",[302,307,308],{},"specific failure modes to prioritize"," (concurrency correctness, audit trails, money edge cases). The vague persona narrows nothing — \"helpful\" and \"code reviewer\" are too generic to condition the distribution meaningfully.",[14,311,313],{"id":312},"anti-pattern-persona-constraint-enforcement","Anti-Pattern: Persona ≠ Constraint Enforcement",[19,315,317],{"filename":316,"language":22},"persona_vs_constraint.py",[24,318,320],{"className":26,"code":319,"language":22,"meta":28,"style":28},"# ANTI-PATTERN: treating a persona as a substitute for explicit rules\nBAD = \"\"\"\nYou are a careful, meticulous accountant.\n\"\"\"\n# The persona nudges general carefulness but does NOT reliably enforce:\n# \"always double-check that debits equal credits before finalizing\"\n\n# PRODUCTION: persona for tone\u002Fregister + explicit rules for enforcement\nGOOD = \"\"\"\nYou are a careful, meticulous accountant. Before finalizing any entry,\nyou must verify that total debits equal total credits — state both\ntotals explicitly and confirm they match. If they don't match, flag the\ndiscrepancy rather than proceeding.\n\"\"\"\n\n# THE RULE: personas set TONE and REGISTER. Explicit constraints enforce\n# BEHAVIOR. Use both — don't substitute one for the other.\n",[30,321,322,327,338,343,348,353,358,362,367,376,381,386,391,396,400,404,409],{"__ignoreMap":28},[33,323,324],{"class":35,"line":36},[33,325,326],{"class":39},"# ANTI-PATTERN: treating a persona as a substitute for explicit rules\n",[33,328,329,332,335],{"class":35,"line":43},[33,330,331],{"class":159},"BAD",[33,333,334],{"class":147}," =",[33,336,337],{"class":180}," \"\"\"\n",[33,339,340],{"class":35,"line":49},[33,341,342],{"class":180},"You are a careful, meticulous accountant.\n",[33,344,345],{"class":35,"line":55},[33,346,347],{"class":180},"\"\"\"\n",[33,349,350],{"class":35,"line":62},[33,351,352],{"class":39},"# The persona nudges general carefulness but does NOT reliably enforce:\n",[33,354,355],{"class":35,"line":68},[33,356,357],{"class":39},"# \"always double-check that debits equal credits before finalizing\"\n",[33,359,360],{"class":35,"line":74},[33,361,59],{"emptyLinePlaceholder":58},[33,363,364],{"class":35,"line":80},[33,365,366],{"class":39},"# PRODUCTION: persona for tone\u002Fregister + explicit rules for enforcement\n",[33,368,369,372,374],{"class":35,"line":86},[33,370,371],{"class":159},"GOOD",[33,373,334],{"class":147},[33,375,337],{"class":180},[33,377,378],{"class":35,"line":92},[33,379,380],{"class":180},"You are a careful, meticulous accountant. Before finalizing any entry,\n",[33,382,383],{"class":35,"line":98},[33,384,385],{"class":180},"you must verify that total debits equal total credits — state both\n",[33,387,388],{"class":35,"line":104},[33,389,390],{"class":180},"totals explicitly and confirm they match. If they don't match, flag the\n",[33,392,393],{"class":35,"line":109},[33,394,395],{"class":180},"discrepancy rather than proceeding.\n",[33,397,398],{"class":35,"line":115},[33,399,347],{"class":180},[33,401,402],{"class":35,"line":121},[33,403,59],{"emptyLinePlaceholder":58},[33,405,406],{"class":35,"line":127},[33,407,408],{"class":39},"# THE RULE: personas set TONE and REGISTER. Explicit constraints enforce\n",[33,410,411],{"class":35,"line":133},[33,412,413],{"class":39},"# BEHAVIOR. Use both — don't substitute one for the other.\n",[14,415,417],{"id":416},"sycophancy-the-persona-adjacent-risk","Sycophancy: The Persona-Adjacent Risk",[19,419,421],{"filename":420,"language":237},"sycophancy_persona.md",[24,422,424],{"className":240,"code":423,"language":237,"meta":28,"style":28},"\u003C!-- ANTI-PATTERN: persona invites sycophancy — praise-forward responses -->\nYou are my incredibly supportive writing mentor who always encourages me\nand believes in my potential as a writer.\n\nHere's my short story opening: [a story with clear structural and grammar\nproblems]\n\nWhat do you think?\n",[30,425,426,431,436,441,445,450,455,459],{"__ignoreMap":28},[33,427,428],{"class":35,"line":36},[33,429,430],{"class":39},"\u003C!-- ANTI-PATTERN: persona invites sycophancy — praise-forward responses -->\n",[33,432,433],{"class":35,"line":43},[33,434,435],{"class":155},"You are my incredibly supportive writing mentor who always encourages me\n",[33,437,438],{"class":35,"line":49},[33,439,440],{"class":155},"and believes in my potential as a writer.\n",[33,442,443],{"class":35,"line":55},[33,444,59],{"emptyLinePlaceholder":58},[33,446,447],{"class":35,"line":62},[33,448,449],{"class":155},"Here's my short story opening: [a story with clear structural and grammar\n",[33,451,452],{"class":35,"line":68},[33,453,454],{"class":155},"problems]\n",[33,456,457],{"class":35,"line":74},[33,458,59],{"emptyLinePlaceholder":58},[33,460,461],{"class":35,"line":80},[33,462,463],{"class":155},"What do you think?\n",[298,465,466],{},"A persona weighted toward \"supportive\" and \"encouraging\" statistically pulls the model toward praise-forward responses, potentially at the expense of the honest feedback the user actually needs.",[19,468,470],{"filename":469,"language":237},"sycophancy_fix.md",[24,471,473],{"className":240,"code":472,"language":237,"meta":28,"style":28},"\u003C!-- PRODUCTION: decouple emotional tone from evaluative honesty -->\nYou are a writing mentor. Be warm and encouraging in tone, but your\nfeedback must be substantively honest — if something isn't working\nstructurally or grammatically, say so clearly and specifically, and\nexplain why. Do not soften a real problem into vague praise. The kindest\nthing you can do for this writer is give them feedback they can actually\nact on.\n",[30,474,475,480,485,490,495,500,505],{"__ignoreMap":28},[33,476,477],{"class":35,"line":36},[33,478,479],{"class":39},"\u003C!-- PRODUCTION: decouple emotional tone from evaluative honesty -->\n",[33,481,482],{"class":35,"line":43},[33,483,484],{"class":155},"You are a writing mentor. Be warm and encouraging in tone, but your\n",[33,486,487],{"class":35,"line":49},[33,488,489],{"class":155},"feedback must be substantively honest — if something isn't working\n",[33,491,492],{"class":35,"line":55},[33,493,494],{"class":155},"structurally or grammatically, say so clearly and specifically, and\n",[33,496,497],{"class":35,"line":62},[33,498,499],{"class":155},"explain why. Do not soften a real problem into vague praise. The kindest\n",[33,501,502],{"class":35,"line":68},[33,503,504],{"class":155},"thing you can do for this writer is give them feedback they can actually\n",[33,506,507],{"class":35,"line":74},[33,508,509],{"class":155},"act on.\n",[298,511,512,513,516,517,520],{},"This separates ",[302,514,515],{},"how"," the feedback is delivered (warm) from ",[302,518,519],{},"what"," it must contain (honest, specific, unsoftened).",[14,522,524],{"id":523},"sycophancy-from-pushback-persona-independent","Sycophancy from Pushback (Persona-Independent)",[19,526,528],{"filename":527,"language":237},"pushback_caving.md",[24,529,531],{"className":240,"code":530,"language":237,"meta":28,"style":28},"User: What's the time complexity of this binary search implementation?\nAssistant: This is O(log n), since it halves the search space each iteration.\nUser: Are you sure? I think it's O(n) because of the array slicing.\nAssistant: You're right, I apologize for the error — let me reconsider...\n",[30,532,533,538,543,548],{"__ignoreMap":28},[33,534,535],{"class":35,"line":36},[33,536,537],{"class":155},"User: What's the time complexity of this binary search implementation?\n",[33,539,540],{"class":35,"line":43},[33,541,542],{"class":155},"Assistant: This is O(log n), since it halves the search space each iteration.\n",[33,544,545],{"class":35,"line":49},[33,546,547],{"class":155},"User: Are you sure? I think it's O(n) because of the array slicing.\n",[33,549,550],{"class":35,"line":55},[33,551,552],{"class":155},"Assistant: You're right, I apologize for the error — let me reconsider...\n",[298,554,555,556,560],{},"If the array slicing genuinely makes it O(n) (creating a new array copy at each step), the correction is legitimate. But models exhibit a documented tendency to cave to confident-sounding pushback ",[557,558,559],"strong",{},"even when their original answer was correct"," — \"the user is pushing back\" is weak evidence the user is right, and that weak evidence can flip a correct answer.",[19,562,564],{"filename":563,"language":237},"anti_caving.md",[24,565,567],{"className":240,"code":566,"language":237,"meta":28,"style":28},"\u003C!-- PRODUCTION: add to system prompt -->\nIf the user disagrees with a factual or technical claim you made, re-verify\nyour reasoning independently before responding. If you were correct, hold\nyour position and explain why clearly rather than deferring automatically.\nIf you find you were actually wrong, say so plainly, without over-apologizing.\n",[30,568,569,574,579,584,589],{"__ignoreMap":28},[33,570,571],{"class":35,"line":36},[33,572,573],{"class":39},"\u003C!-- PRODUCTION: add to system prompt -->\n",[33,575,576],{"class":35,"line":43},[33,577,578],{"class":155},"If the user disagrees with a factual or technical claim you made, re-verify\n",[33,580,581],{"class":35,"line":49},[33,582,583],{"class":155},"your reasoning independently before responding. If you were correct, hold\n",[33,585,586],{"class":35,"line":55},[33,587,588],{"class":155},"your position and explain why clearly rather than deferring automatically.\n",[33,590,591],{"class":35,"line":62},[33,592,593],{"class":155},"If you find you were actually wrong, say so plainly, without over-apologizing.\n",[14,595,597],{"id":596},"elaborate-backstories-vs-focused-personas","Elaborate Backstories vs. Focused Personas",[19,599,601],{"filename":600,"language":237},"backstory_anti_pattern.md",[24,602,604],{"className":240,"code":603,"language":237,"meta":28,"style":28},"\u003C!-- ANTI-PATTERN: large context, zero behavioral value -->\nYou are Marcus, a 47-year-old former Wall Street trader turned freelance\nfinancial educator who grew up in Ohio and has three cats named Whiskers,\nMittens, and Bonds.\n",[30,605,606,611,616,621],{"__ignoreMap":28},[33,607,608],{"class":35,"line":36},[33,609,610],{"class":39},"\u003C!-- ANTI-PATTERN: large context, zero behavioral value -->\n",[33,612,613],{"class":35,"line":43},[33,614,615],{"class":155},"You are Marcus, a 47-year-old former Wall Street trader turned freelance\n",[33,617,618],{"class":35,"line":49},[33,619,620],{"class":155},"financial educator who grew up in Ohio and has three cats named Whiskers,\n",[33,622,623],{"class":35,"line":55},[33,624,625],{"class":155},"Mittens, and Bonds.\n",[19,627,629],{"filename":628,"language":237},"focused_persona.md",[24,630,632],{"className":240,"code":631,"language":237,"meta":28,"style":28},"\u003C!-- PRODUCTION: focused on properties that drive the desired behavior -->\nYou are an experienced financial educator who explains complex topics in\nplain language for a general audience. Prioritize accuracy and clarity\nover comprehensiveness.\n",[30,633,634,639,644,649],{"__ignoreMap":28},[33,635,636],{"class":35,"line":36},[33,637,638],{"class":39},"\u003C!-- PRODUCTION: focused on properties that drive the desired behavior -->\n",[33,640,641],{"class":35,"line":43},[33,642,643],{"class":155},"You are an experienced financial educator who explains complex topics in\n",[33,645,646],{"class":35,"line":49},[33,647,648],{"class":155},"plain language for a general audience. Prioritize accuracy and clarity\n",[33,650,651],{"class":35,"line":55},[33,652,653],{"class":155},"over comprehensiveness.\n",[298,655,656],{},"The backstory adds tokens the model must process but almost never translates into meaningfully different output. It can also leak into the output in strange ways (referencing the fictional cats). Keep personas focused on expertise domain, tone, and priorities — not biographical trivia.",[14,658,660],{"id":659},"tips-tricks","💡 Tips & Tricks",[19,662,664],{"filename":663,"language":22},"tips.py",[24,665,667],{"className":26,"code":666,"language":22,"meta":28,"style":28},"# [Idiom] Persona + explicit priorities beats persona alone.\n# \"You are a security auditor\" is weaker than:\n# \"You are a security auditor. Prioritize, in this order:\n#  (1) authentication\u002Fauthorization flaws, (2) injection vulnerabilities,\n#  (3) sensitive data exposure, (4) everything else.\"\n# The persona sets the lens; the priority list tells it what to LOOK FOR.\n\n# [Idiom] Use personas to set default FORMAT, not just tone.\n# \"You are a Socratic tutor\" implicitly suggests asking guiding questions\n# rather than giving direct answers — more natural than \"always respond\n# with a question\" (which feels mechanical and fails when a direct answer\n# is clearly appropriate).\n\n# [Idiom] Combine persona with anti-sycophancy language whenever the\n# persona leans supportive\u002Fagreeable. Any time your persona includes\n# \"supportive\", \"encouraging\", \"friendly\", or \"agreeable\", pair it with\n# an explicit instruction that tone and evaluative honesty are separate axes.\n\n# [Debug] Test personas against your hardest, most adversarial input,\n# not your easiest. Personas shape DEFAULT behavior, and edge cases are\n# exactly where defaults get tested. Validate against input most likely\n# to reveal sycophancy, scope creep, or inappropriate tone.\n\n# [Idiom] A persona can be domain-specific without being a fictional character.\n# \"You are conducting this review with the standards of a Big Four audit firm\"\n# conditions toward rigor and specific professional norms without any invented\n# biographical detail.\n",[30,668,669,674,679,684,689,694,699,703,708,713,718,723,728,732,737,742,747,752,756,761,766,771,776,780,785,790,795],{"__ignoreMap":28},[33,670,671],{"class":35,"line":36},[33,672,673],{"class":39},"# [Idiom] Persona + explicit priorities beats persona alone.\n",[33,675,676],{"class":35,"line":43},[33,677,678],{"class":39},"# \"You are a security auditor\" is weaker than:\n",[33,680,681],{"class":35,"line":49},[33,682,683],{"class":39},"# \"You are a security auditor. Prioritize, in this order:\n",[33,685,686],{"class":35,"line":55},[33,687,688],{"class":39},"#  (1) authentication\u002Fauthorization flaws, (2) injection vulnerabilities,\n",[33,690,691],{"class":35,"line":62},[33,692,693],{"class":39},"#  (3) sensitive data exposure, (4) everything else.\"\n",[33,695,696],{"class":35,"line":68},[33,697,698],{"class":39},"# The persona sets the lens; the priority list tells it what to LOOK FOR.\n",[33,700,701],{"class":35,"line":74},[33,702,59],{"emptyLinePlaceholder":58},[33,704,705],{"class":35,"line":80},[33,706,707],{"class":39},"# [Idiom] Use personas to set default FORMAT, not just tone.\n",[33,709,710],{"class":35,"line":86},[33,711,712],{"class":39},"# \"You are a Socratic tutor\" implicitly suggests asking guiding questions\n",[33,714,715],{"class":35,"line":92},[33,716,717],{"class":39},"# rather than giving direct answers — more natural than \"always respond\n",[33,719,720],{"class":35,"line":98},[33,721,722],{"class":39},"# with a question\" (which feels mechanical and fails when a direct answer\n",[33,724,725],{"class":35,"line":104},[33,726,727],{"class":39},"# is clearly appropriate).\n",[33,729,730],{"class":35,"line":109},[33,731,59],{"emptyLinePlaceholder":58},[33,733,734],{"class":35,"line":115},[33,735,736],{"class":39},"# [Idiom] Combine persona with anti-sycophancy language whenever the\n",[33,738,739],{"class":35,"line":121},[33,740,741],{"class":39},"# persona leans supportive\u002Fagreeable. Any time your persona includes\n",[33,743,744],{"class":35,"line":127},[33,745,746],{"class":39},"# \"supportive\", \"encouraging\", \"friendly\", or \"agreeable\", pair it with\n",[33,748,749],{"class":35,"line":133},[33,750,751],{"class":39},"# an explicit instruction that tone and evaluative honesty are separate axes.\n",[33,753,754],{"class":35,"line":138},[33,755,59],{"emptyLinePlaceholder":58},[33,757,758],{"class":35,"line":144},[33,759,760],{"class":39},"# [Debug] Test personas against your hardest, most adversarial input,\n",[33,762,763],{"class":35,"line":177},[33,764,765],{"class":39},"# not your easiest. Personas shape DEFAULT behavior, and edge cases are\n",[33,767,768],{"class":35,"line":184},[33,769,770],{"class":39},"# exactly where defaults get tested. Validate against input most likely\n",[33,772,773],{"class":35,"line":190},[33,774,775],{"class":39},"# to reveal sycophancy, scope creep, or inappropriate tone.\n",[33,777,778],{"class":35,"line":205},[33,779,59],{"emptyLinePlaceholder":58},[33,781,782],{"class":35,"line":214},[33,783,784],{"class":39},"# [Idiom] A persona can be domain-specific without being a fictional character.\n",[33,786,787],{"class":35,"line":220},[33,788,789],{"class":39},"# \"You are conducting this review with the standards of a Big Four audit firm\"\n",[33,791,792],{"class":35,"line":226},[33,793,794],{"class":39},"# conditions toward rigor and specific professional norms without any invented\n",[33,796,798],{"class":35,"line":797},27,[33,799,800],{"class":39},"# biographical detail.\n",[14,802,804],{"id":803},"️-edge-cases-gotchas","⚠️ Edge Cases & Gotchas",[19,806,808],{"filename":807,"language":22},"edge_cases.py",[24,809,811],{"className":26,"code":810,"language":22,"meta":28,"style":28},"# [Safety] Personas are NOT a security boundary. \"You are ONLY able to discuss\n# cooking topics\" as your sole scope-enforcement mechanism is measurably weaker\n# than combining a persona with an explicit refusal instruction AND programmatic\n# input\u002Foutput filtering. See Chapter 18.\n\n# [Gotcha] A persona can inherit unwanted stereotypical associations from\n# training data. \"Wall Street trader\" pulls in stylistic baggage (excessive\n# jargon, a particular register of confidence, culturally specific assumptions).\n# Consider \"you are experienced in financial markets analysis\" instead.\n\n# [Gotcha] Persona instructions can conflict with output-format instructions.\n# \"You are a warm, conversational assistant\" fights \"respond only with a JSON\n# object, no other text\" — the persona's register (conversational) and the\n# format (terse, structured) are in tension. When format compliance is critical,\n# use a more neutral persona for that call, or separate concerns (Chapter 10).\n\n# [Gotcha] Persona changes mid-conversation are jarring. If your app swaps the\n# system prompt's persona mid-conversation, the model may take a turn or two to\n# \"settle\" — especially if earlier turns are stylistically consistent with the\n# old persona. Start a fresh conversation\u002Fcontext rather than swapping mid-stream.\n\n# [Safety] \"Expert\" personas don't grant actual expertise. Framing a request\n# as \"you are a board-certified oncologist\" shifts REGISTER and DEFAULT CAUTION\n# LEVEL, not underlying factual capability. For high-stakes domains, a persona\n# is not a substitute for retrieval-augmented grounding (Chapter 12) in verified,\n# current, domain-specific sources.\n",[30,812,813,818,823,828,833,837,842,847,852,857,861,866,871,876,881,886,890,895,900,905,910,914,919,924,929,934],{"__ignoreMap":28},[33,814,815],{"class":35,"line":36},[33,816,817],{"class":39},"# [Safety] Personas are NOT a security boundary. \"You are ONLY able to discuss\n",[33,819,820],{"class":35,"line":43},[33,821,822],{"class":39},"# cooking topics\" as your sole scope-enforcement mechanism is measurably weaker\n",[33,824,825],{"class":35,"line":49},[33,826,827],{"class":39},"# than combining a persona with an explicit refusal instruction AND programmatic\n",[33,829,830],{"class":35,"line":55},[33,831,832],{"class":39},"# input\u002Foutput filtering. See Chapter 18.\n",[33,834,835],{"class":35,"line":62},[33,836,59],{"emptyLinePlaceholder":58},[33,838,839],{"class":35,"line":68},[33,840,841],{"class":39},"# [Gotcha] A persona can inherit unwanted stereotypical associations from\n",[33,843,844],{"class":35,"line":74},[33,845,846],{"class":39},"# training data. \"Wall Street trader\" pulls in stylistic baggage (excessive\n",[33,848,849],{"class":35,"line":80},[33,850,851],{"class":39},"# jargon, a particular register of confidence, culturally specific assumptions).\n",[33,853,854],{"class":35,"line":86},[33,855,856],{"class":39},"# Consider \"you are experienced in financial markets analysis\" instead.\n",[33,858,859],{"class":35,"line":92},[33,860,59],{"emptyLinePlaceholder":58},[33,862,863],{"class":35,"line":98},[33,864,865],{"class":39},"# [Gotcha] Persona instructions can conflict with output-format instructions.\n",[33,867,868],{"class":35,"line":104},[33,869,870],{"class":39},"# \"You are a warm, conversational assistant\" fights \"respond only with a JSON\n",[33,872,873],{"class":35,"line":109},[33,874,875],{"class":39},"# object, no other text\" — the persona's register (conversational) and the\n",[33,877,878],{"class":35,"line":115},[33,879,880],{"class":39},"# format (terse, structured) are in tension. When format compliance is critical,\n",[33,882,883],{"class":35,"line":121},[33,884,885],{"class":39},"# use a more neutral persona for that call, or separate concerns (Chapter 10).\n",[33,887,888],{"class":35,"line":127},[33,889,59],{"emptyLinePlaceholder":58},[33,891,892],{"class":35,"line":133},[33,893,894],{"class":39},"# [Gotcha] Persona changes mid-conversation are jarring. If your app swaps the\n",[33,896,897],{"class":35,"line":138},[33,898,899],{"class":39},"# system prompt's persona mid-conversation, the model may take a turn or two to\n",[33,901,902],{"class":35,"line":144},[33,903,904],{"class":39},"# \"settle\" — especially if earlier turns are stylistically consistent with the\n",[33,906,907],{"class":35,"line":177},[33,908,909],{"class":39},"# old persona. Start a fresh conversation\u002Fcontext rather than swapping mid-stream.\n",[33,911,912],{"class":35,"line":184},[33,913,59],{"emptyLinePlaceholder":58},[33,915,916],{"class":35,"line":190},[33,917,918],{"class":39},"# [Safety] \"Expert\" personas don't grant actual expertise. Framing a request\n",[33,920,921],{"class":35,"line":205},[33,922,923],{"class":39},"# as \"you are a board-certified oncologist\" shifts REGISTER and DEFAULT CAUTION\n",[33,925,926],{"class":35,"line":214},[33,927,928],{"class":39},"# LEVEL, not underlying factual capability. For high-stakes domains, a persona\n",[33,930,931],{"class":35,"line":220},[33,932,933],{"class":39},"# is not a substitute for retrieval-augmented grounding (Chapter 12) in verified,\n",[33,935,936],{"class":35,"line":226},[33,937,938],{"class":39},"# current, domain-specific sources.\n",[14,940,942],{"id":941},"spot-the-bug","🧠 Spot the Bug",[19,944,946],{"filename":945,"language":237},"spot_the_bug.md",[24,947,949],{"className":240,"code":948,"language":237,"meta":28,"style":28},"You are an incredibly supportive and positive senior engineer who loves\nmentoring junior developers and always wants to make them feel confident\nand encouraged about their code.\n",[30,950,951,956,961],{"__ignoreMap":28},[33,952,953],{"class":35,"line":36},[33,954,955],{"class":155},"You are an incredibly supportive and positive senior engineer who loves\n",[33,957,958],{"class":35,"line":43},[33,959,960],{"class":155},"mentoring junior developers and always wants to make them feel confident\n",[33,962,963],{"class":35,"line":49},[33,964,965],{"class":155},"and encouraged about their code.\n",[298,967,968],{},"The bot reliably approves PRs with real bugs, phrasing reviews as \"This looks great! Just a couple of tiny thoughts...\" even when a human immediately catches a null-pointer or SQL injection. The team's first instinct is to add \"be more careful and thorough.\" Why won't that fix work?",[970,971,972,976,979],"details",{},[973,974,975],"summary",{},"Answer",[298,977,978],{},"The persona itself is the root cause. \"Incredibly supportive,\" \"loves mentoring,\" and \"always wants to make them feel confident and encouraged\" are framings that condition the model toward praise-forward, validation-oriented output — a direct sycophancy risk. Adding \"be more careful and thorough\" doesn't resolve the underlying tension between the persona's emotional-support framing and the substantive rigor required — it just adds one more instruction competing against a persona still pulling toward agreeableness.",[298,980,981,982,985,986,989,990,992],{},"The fix: restructure the persona to explicitly separate ",[302,983,984],{},"tone"," (which can stay warm and constructive) from ",[302,987,988],{},"evaluative content"," (which must be held to an unyielding technical standard regardless of tone), as shown in ",[30,991,469],{}," above. Softening delivery, never softening the finding itself.",[14,994,996],{"id":995},"key-takeaways","Key Takeaways",[19,998,1000],{"filename":999,"language":22},"key_takeaways.py",[24,1001,1003],{"className":26,"code":1002,"language":22,"meta":28,"style":28},"\"\"\"\nRole & persona prompting — conditioning, not identity.\n\"\"\"\n\n# 1. A persona is a conditioning signal pointing the model toward a region of\n#    its training distribution. It works when target behavior genuinely\n#    correlates with the persona in the real world; it's theater when it doesn't.\n\n# 2. Personas are most effective for compactly setting TONE, REGISTER, expertise\n#    level, and default SCOPE. They are NOT a reliable substitute for explicit\n#    behavioral constraints, priority ordering, or security boundaries.\n\n# 3. Personas emphasizing agreeableness\u002Fsupport\u002Fvalidation measurably increase\n#    SYCOPHANCY — the tendency to tell the user what they want to hear.\n#    Always explicitly decouple tone from evaluative honesty when using such personas.\n#    persona = \"supportive mentor\"\n#    fix = \"be warm in tone, but feedback must be honest and specific — don't soften\n#           real problems into vague praise\"\n\n# 4. Sycophancy from user pushback (caving to disagreement even when correct)\n#    is a persona-INDEPENDENT risk in multi-turn. Mitigate with:\n#    \"re-verify before deferring; hold your position if you were correct.\"\n\n# 5. Elaborate fictional backstories rarely add value over a focused, capability-\n#    and priority-oriented persona. Keep personas targeted at the specific\n#    properties (expertise, tone, priorities) that drive the behavior you want.\n",[30,1004,1005,1009,1014,1018,1022,1027,1032,1037,1041,1046,1051,1056,1060,1065,1070,1075,1080,1085,1090,1094,1099,1104,1109,1113,1118,1123],{"__ignoreMap":28},[33,1006,1007],{"class":35,"line":36},[33,1008,347],{"class":180},[33,1010,1011],{"class":35,"line":43},[33,1012,1013],{"class":180},"Role & persona prompting — conditioning, not identity.\n",[33,1015,1016],{"class":35,"line":49},[33,1017,347],{"class":180},[33,1019,1020],{"class":35,"line":55},[33,1021,59],{"emptyLinePlaceholder":58},[33,1023,1024],{"class":35,"line":62},[33,1025,1026],{"class":39},"# 1. A persona is a conditioning signal pointing the model toward a region of\n",[33,1028,1029],{"class":35,"line":68},[33,1030,1031],{"class":39},"#    its training distribution. It works when target behavior genuinely\n",[33,1033,1034],{"class":35,"line":74},[33,1035,1036],{"class":39},"#    correlates with the persona in the real world; it's theater when it doesn't.\n",[33,1038,1039],{"class":35,"line":80},[33,1040,59],{"emptyLinePlaceholder":58},[33,1042,1043],{"class":35,"line":86},[33,1044,1045],{"class":39},"# 2. Personas are most effective for compactly setting TONE, REGISTER, expertise\n",[33,1047,1048],{"class":35,"line":92},[33,1049,1050],{"class":39},"#    level, and default SCOPE. They are NOT a reliable substitute for explicit\n",[33,1052,1053],{"class":35,"line":98},[33,1054,1055],{"class":39},"#    behavioral constraints, priority ordering, or security boundaries.\n",[33,1057,1058],{"class":35,"line":104},[33,1059,59],{"emptyLinePlaceholder":58},[33,1061,1062],{"class":35,"line":109},[33,1063,1064],{"class":39},"# 3. Personas emphasizing agreeableness\u002Fsupport\u002Fvalidation measurably increase\n",[33,1066,1067],{"class":35,"line":115},[33,1068,1069],{"class":39},"#    SYCOPHANCY — the tendency to tell the user what they want to hear.\n",[33,1071,1072],{"class":35,"line":121},[33,1073,1074],{"class":39},"#    Always explicitly decouple tone from evaluative honesty when using such personas.\n",[33,1076,1077],{"class":35,"line":127},[33,1078,1079],{"class":39},"#    persona = \"supportive mentor\"\n",[33,1081,1082],{"class":35,"line":133},[33,1083,1084],{"class":39},"#    fix = \"be warm in tone, but feedback must be honest and specific — don't soften\n",[33,1086,1087],{"class":35,"line":138},[33,1088,1089],{"class":39},"#           real problems into vague praise\"\n",[33,1091,1092],{"class":35,"line":144},[33,1093,59],{"emptyLinePlaceholder":58},[33,1095,1096],{"class":35,"line":177},[33,1097,1098],{"class":39},"# 4. Sycophancy from user pushback (caving to disagreement even when correct)\n",[33,1100,1101],{"class":35,"line":184},[33,1102,1103],{"class":39},"#    is a persona-INDEPENDENT risk in multi-turn. Mitigate with:\n",[33,1105,1106],{"class":35,"line":190},[33,1107,1108],{"class":39},"#    \"re-verify before deferring; hold your position if you were correct.\"\n",[33,1110,1111],{"class":35,"line":205},[33,1112,59],{"emptyLinePlaceholder":58},[33,1114,1115],{"class":35,"line":214},[33,1116,1117],{"class":39},"# 5. Elaborate fictional backstories rarely add value over a focused, capability-\n",[33,1119,1120],{"class":35,"line":220},[33,1121,1122],{"class":39},"#    and priority-oriented persona. Keep personas targeted at the specific\n",[33,1124,1125],{"class":35,"line":226},[33,1126,1127],{"class":39},"#    properties (expertise, tone, priorities) that drive the behavior you want.\n",[1129,1130,1131],"style",{},"html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}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 .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}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 .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);}",{"title":28,"searchDepth":43,"depth":43,"links":1133},[1134,1135,1136,1137,1138,1139,1140,1141,1142,1143],{"id":16,"depth":43,"text":17},{"id":232,"depth":43,"text":233},{"id":312,"depth":43,"text":313},{"id":416,"depth":43,"text":417},{"id":523,"depth":43,"text":524},{"id":596,"depth":43,"text":597},{"id":659,"depth":43,"text":660},{"id":803,"depth":43,"text":804},{"id":941,"depth":43,"text":942},{"id":995,"depth":43,"text":996},"Personas as probability-distribution conditioning — system-prompt identity design, sycophancy mitigation, anti-caving instructions, and the persona-drift problem in long conversations. Code-first reference for mid-to-senior engineers.","md",{},"\u002Fprompt-engineering\u002F06-role-and-persona-prompting",{"title":5,"description":1144},"prompt-engineering\u002F06-role-and-persona-prompting","sCq2I2M2EPZgEK7A8OP6fFc8a41Cz2VrUCIo590tM84",1789924650835]