Most “prompt engineering” advice is vague nonsense. “Be specific.” “Provide context.” Thanks, very helpful.

Here are 7 concrete patterns I use daily that make a measurable difference when working with AI coding tools.

Pattern 1: The Constraint Sandwich

Structure: Task → Constraints → Task reminder

WC-----WrorinUMRIMitssuenatetestcxertulaaoru3tinhnd0hPnlaeeytynaltsdtifh:tltynuoheupennepesciltfsnehiuttionaeonncnrfttdnswiaa(iortitndisho_tlnvthiaahablletrisaedevrm:ayaelibxi(loadnocaoalttd,etdcshrroieenersasmdssta-eoripsnala:ir(natRstdyFtsdCr.rp)ea6sc5sk3ea1sg).es)

Why it works: AI models tend to forget constraints mentioned at the beginning by the time they start generating. Repeating the core constraint at the end keeps it in focus.

Without this pattern: You’ll get a function that uses email-validator package, returns just a boolean, and is 60 lines long.

Pattern 2: The Negative Example

Structure: Show what you DON’T want, then what you DO want.

IDteD----GOrxOenNycCLRDne':etaoeoeeTrprhtgtnrdeteicu'adstshwrtteouEu:inerlxrsterttcnphaxtoheepphri=p{ccpoest"iorsh:piefnoeearoritprnonrcerirdcoxinolearetatriss"xtens:c(erhg_eernad:speHanfattqTldotriuTlra(oePei(ensrnai)stsrgnn}_topiarcAudtoPt,uddI)seeut.escaneoidrdlp_esoisidtn)ot.theclient

Why it works: AI models learn from millions of code examples, including bad ones. Showing the anti-pattern explicitly prevents the model from falling into the most common trap.

Pattern 3: The Role Lock

Structure: Assign a specific expert role with domain knowledge.

YRoeuviaerwetahissendiaotraPpyrtohcoenssdienvgelfoupnecrtiwohnoasnpdecsiuaglgiezsetsiimnprhoivgehm-epnetrsf.ormancedatapipelines.You'veworkedextensivelywithApacheKafka,Redis,andPostgreSQL.Youpreferfunctionalprogrammingpatternsandalwaysconsidermemoryefficiency.

Why it works: The role constrains the model’s response distribution. A “senior Python developer” will suggest different things than a generic assistant — more idiomatic code, better patterns, awareness of production concerns.

Pro tip: Match the role to your actual needs. Don’t say “world’s best developer” — say “backend developer experienced with Django and PostgreSQL” for more relevant suggestions.

Pattern 4: The Chain of Files

Structure: Feed files in dependency order with clear labels.

I=[=[=[T'=p=p=phm=a=a=aessswFtFtFtboieieieurlllgkececec:iooon1d2d3dUg:e:e:es]]]eomarrnouosdtuaehtwl/eibsmstu/i/hgudlsdoeielgxnreip.wnitpa.rhyrpeeeyd=.u=p(ts=yBoeUkr=Ge=na=IsuStchHaeEnnRtEsi)tcia=lt=li=oanccfelsosw.prHoetreectaerdertohueterse.leFvianndttfhieleiss:sueinthemiddleware.

Why it works: AI needs context to understand code. But dumping your entire codebase doesn’t help — it dilutes the signal. Feeding files in dependency order with clear labels gives the model a mental map of your system.

The label “BUG IS HERE” focuses attention on the right file while still providing necessary context from dependencies.

Pattern 5: The Output Template

Structure: Show the exact output format you want.

G`ce`ln`aepsrys"dat"ethT"feoeTnset"#[#r#autse"sesnCts"AeAsAsiast[rtcusetl_Orutlsrcf[naptettuosenrelrcgc=trsaeseoettcnedcsseaaneauDlrt]llficiectosuonurcl_cl=oanea=tutathnemde[it_ee_es:d]sdxi(cipfssrseuceiccnolbotcufiuetn)nndit:gt]o(nfw[.uhpnaaUctrstaeitmohstni]h.s)i"s"t"eesxtasc]t."f"o"rmat:

Include tests for: happy path, zero values, negative values, boundary conditions, and invalid input types.

#*#*WShPtyartuitctetruwnroer6:k:*s*:T*hB*euiWIlindtchrcoeoummtepnlateaxtletmBhpuilinalgtdse,inAIexgpelniecriattesstetpess.tsinwhateverformatitfeelslikesometimespytest,sometimesunittest,sometimesbarefunctions.Thetemplateensuresconsistent,copy-pasteableoutput.

I need a REST API for a todo app. Let’s build it step by step.

Step 1: Generate just the data models (SQLAlchemy).

  • Todo: id, title, description, status, created_at, updated_at
  • User: id, email, hashed_password, created_at Wait for my approval before proceeding.
Thenafterreviewing:

Good. Step 2: Generate the CRUD operations for Todo model.

  • Use async SQLAlchemy
  • Include pagination for list endpoint
  • Include filtering by status Wait for approval.
#**#*WAShnPtytaritui-tctpetaruwtnrotere7:kr:*sn*::T**hP**eroADDvsoeiknbdi'uentgggsaiyfsnmokgprtfDoaoimnrasl,e"onagctuoicenrotemepxAltPe,Iteaantpdroowndhcuaecttpiyrooonud-'urvceeeasdtyrmieAedPdiI.ocwriethreasuutlht,stbeesctaiunsge,tDhoeckmeord,elCIi/sCDj,ugagnldindgoctuomoenmtaantyiodne"ciisnioonnsespirmoumlptta.neYoouus'llyl.gBerteaakisnugpeirtfiicnitaolsvteerpssiolnetosfyeovuercyotuhrisneg-.coTrhraetctsaeiadr,lythaendingcertembeentttaelraopuptrpouatchatiseasclhowsetrage.ifyou'rejustprototypingorexploringanidea,asinglebroadpromptisperfectlyfine.

Bug: API returns 500 error intermittently (about 1 in 20 requests).

Stack trace: [paste stack trace]

Context:

  • This started after deploying commit abc123 (added connection pooling)
  • Only happens under load (>50 req/sec)
  • Database connections look normal in monitoring
  • No memory leaks detected

Already tried:

  • Increasing connection pool size (no change)
  • Adding request timeout (no change)
  • Rolling back connection pooling (fixes it, but we need pooling for performance)

What are the most likely causes? Rank by probability.

#AAT*#---📦*#lIhT#*Wleh#[[[NhTme1HC*eyhsobsY0ouFweedeeowrrsivesuAseltMeltpIIoeeensamr:twtptiCU*toapwrtgosv*er-aioehdesrkPtlmrti[:satlpnnACA*:tetsagIlI**trdla*eneewsAtuCOrsfnoosodonTnagrsedehsuikliReehlniseCpatewktvoRr"reieaideaaetrtneevcloshtwitroieientaCTCnwcaehrlioadeeapd2Plypnuse0rrm'd2oAtioteTF6mIrnsha:pictpCastweieottWodp"odehPr"lapeAriakevl,cccfs:eet(hklerCuW]ocawhaiA(wt*ghaltI/ireotlhrpoe"GyoCeendkPuosrucnTStdoicoo,aiuwsemwvMnrepCeigcecalmosekrmeapMsTs,ubtgieio/ciiilnocpigocoHglolauntoduliw,uBSes.tuoruh-ynrCsgortW*ldusueei*esrE)lvmt.s.sv]diphsoe(eloTrr/Ywauyh,ypo-ttoeoupeuyaWsrsi'netUotgrdessmI,uek/epia]a?tdAdpn(i]soIeey/-(/nopc)'wtpooptihltsdoleehtesplmes-t1u.wr/rs0bshce/luEoAlcpigvIaiursgeaueroherrcdwsmsyeoe-ophtd-2rteppic0-srtarno2vehtegd6sI.etce/-eit-)cu[orsotlsSbneoiaeuvlpubiaa.sdosobb-encuooT2-rsvuh0c1iete2o5bt6d+ehiws/eishp)-Pnae2R]gatc0s(si2/hdtf6wtyihi/etofec)epufyks'et.:vrwo/eeao/nnlzattil.mdrwaaeatnaytedewyorufs.dsoalundebedss,istnawgtcahksca.toncinonshmgto)rweaviyenortuysountsehe'astittp.iu*mseh.tAhnedo"urtapnuktbfyropmro"bgaebnielriitcy"anfdormceedsiosctrreu"cttuore"dsptehciinfkiicnganidnsutseeafdulo.f"ashotgunlistofpossibilities.