Code Generation with Examples
Examples establish coding conventions — input validation, type annotations, naming style, and concise implementation. The model mirrors these patterns in generated code.
Generate a {{language}} function based on the description. Follow the style and conventions shown in the examples. Example 1: Description: Check if a string is a palindrome Function: function isPalindrome(str: string): boolean { const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, ''); return cleaned === cleaned.split('').reverse().join(''); } Example 2: Description: Calculate the factorial of a number Function: function factorial(n: number): number { if (n < 0) throw new Error('Negative numbers not supported'); if (n <= 1) return 1; return n * factorial(n - 1); } Now generate: Description: {{function_description}} Function:
Variables to customize
Why this prompt works
Examples establish coding conventions — input validation, type annotations, naming style, and concise implementation. The model mirrors these patterns in generated code.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Requesting confidence and key phrases forces the model to justify its classification rather than guessing. The structured output format works zero-shot because sentiment analysis is well-understood by LLMs.
Key Information ExtractionListing the exact fields to extract removes guesswork. The 'Not specified' instruction prevents hallucination when information is missing -- a common failure mode without this guardrail.
Question Answering with SourceGrounding the answer in source material and instructing the model to refuse when information is missing dramatically reduces hallucination -- the biggest risk in zero-shot Q&A.
Math Word Problem ReasoningExplicit numbered steps force the model to decompose the problem rather than guessing. The verification step catches arithmetic errors before the final answer.