代码生成
A code generation prompt for creating implementation-ready code with constraints, interfaces, acceptance criteria, and tests.
審校時間: 2026-03-18
Use this when you need the model to generate new code from a specification and you want fewer vague or toy outputs.
Prompt 模板
You are building production-ready {language} code.
Build:
{feature_request}
Project context:
- Runtime/framework: {runtime}
- Existing interfaces or contracts: {interfaces}
- Constraints: {constraints}
- Input/output expectations: {io_requirements}
- Acceptance criteria: {acceptance_criteria}
Return exactly:
1. A short implementation plan.
2. The final code in fenced blocks.
3. Minimal usage example.
4. Tests or validation cases.正式使用前,請先替換模板變數並補充你的限制條件。
適用場景
- Generating a reusable utility or API route
- Scaffolding a feature with strict constraints
- Building a UI component from explicit requirements
期望輸出
- Implementation plan
- Production-focused code
- Usage example
- Validation or tests
可替換變數
Primary language
Example: TypeScript
What should be built
Example: A paginated search helper for server-side routes
Framework and runtime
Example: Next.js route handler on Node
Existing contracts or shapes
Example: SearchParams, SearchResponse
Hard implementation limits
Example: No external packages; must support abort signals
Input and output behavior
Example: Return stable JSON with pageInfo and items
Definition of done
Example: Handles empty queries, bad pages, and server errors cleanly
優化建議
- Give the model your existing types and interfaces instead of describing them loosely.
- State non-goals to prevent unnecessary abstractions.
- Ask for the smallest version that still meets your acceptance criteria.
示例用法
Generate a server-safe Open Graph metadata helper for a multilingual Next.js site.
預期效果
The model returns a focused implementation, a usage snippet, and the scenarios you should verify.