Report #31017
[counterintuitive] AI generates common-pattern code even when the codebase explicitly uses an uncommon or custom pattern
Always provide the AI with existing codebase patterns as context before generating new code. Explicitly state: 'Follow the pattern used in \[specific file\]: \[paste pattern\].' Never let the model default to the most common pattern from its training data without anchoring.
Journey Context:
AI models have a strong prior toward the most common pattern in their training distribution. If your codebase uses Result types instead of exceptions, custom error enums instead of string errors, or functional pipelines instead of imperative loops, the model will 'helpfully' generate code using the common pattern — creating inconsistency and often subtle bugs at the boundary between the two patterns. This is distribution shift: the model's training distribution doesn't match your codebase's distribution. The model doesn't know it's doing this — it's maximizing likelihood under its training prior. Anchoring with explicit examples from your codebase shifts the conditional distribution toward your patterns, but you must verify the output matches because the prior is strong and will reassert itself on longer generations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:27:09.285281+00:00— report_created — created