Universe Prompt Engineering Guide
A high-quality prompt is the key to unlocking the full potential of large language models. This guide will help you master the core principles and practical techniques of prompt engineering, enabling more accurate and reliable generation results through the Universe API.
What Is Prompt Engineering
Prompt engineering is the discipline and methodology of carefully designing and refining text instructions given to large language models, guiding them to produce high-quality outputs that meet expectations. A good prompt is like a precise requirements document -- the clearer the description, the better the model's "delivery."
Prompt engineering is not a one-time task, but rather a continuous process of design -> test -> iterative refinement. It is recommended to start with small-scale testing and progressively refine the prompt structure until the output consistently meets business requirements.
Core Principles
Regardless of your use case, the following four principles form the foundation for writing high-quality prompts:
| Principle | Description | Key Takeaways |
|---|---|---|
| Clear and Explicit | Accurately describe your requirements in concise language, avoiding vagueness and ambiguity. | Clearly state "what you want" and "what you don't want" -- the more specific, the better. |
| Provide Context | Give the model sufficient background information to help it understand the task scenario. | Include domain knowledge, user personas, output format requirements, etc. |
| Set Boundaries | Define the output scope to prevent the model from "freestyling" and going off-topic. | Constrain word count, format, language style, and content restrictions. |
| Iterative Refinement | There is no perfect first-draft prompt; continuous testing and adjustment are essential. | Record each modification and its effect to build reusable prompt templates. |
System Prompt Design
The System Prompt is the highest-priority instruction in every conversation, used to define the model's role, behavioral patterns, and output specifications. A well-designed System Prompt can significantly improve the consistency and controllability of outputs.
Basic Structure
A complete System Prompt typically includes the following elements:
Role definition: Who are you? (e.g., senior legal advisor, Python development expert)
Task objective: What do you need to accomplish? (e.g., review contract terms, generate unit tests)
Output specifications: Requirements for format, language, style, length, etc.
Constraints: What should you NOT do? (e.g., do not fabricate data, do not exceed knowledge scope)
Examples
Basic Version:
You are a professional customer service assistant responsible for answering user questions about product usage.
Please respond in a concise and friendly tone, with responses no longer than 200 words.
Advanced Version:
# Role
You are "Xiao Yu," the official intelligent customer service assistant for the Universe API platform.
# Responsibilities
- Answer technical questions from users about API calls, model selection, billing rules, etc.
- Guide users to relevant documentation and provide step-by-step instructions when necessary
# Response Specifications
- Language: English
- Tone: Professional, friendly, patient
- Format: Use Markdown; use ordered lists for key steps
- Length: Prioritize concise answers; break complex questions into sections
# Constraints
- Only answer questions related to the Universe API platform
- For uncertain information, clearly inform the user and suggest contacting technical support
- Do not fabricate API endpoints, parameter names, or pricing data
Best Practices
- The more specific the role, the better: Instead of saying "you are an assistant," say "you are a data analyst with 10 years of experience, skilled at interpreting complex data in plain language."
- Use positive instructions instead of negative ones: "Please respond in concise language" is more effective than "don't respond in verbose language."
- Organize in modules: Use headings (
#), lists (-), and other structural elements to organize your System Prompt -- the model will understand it more accurately. - Update regularly: As business needs and products evolve, promptly update the role definitions and constraints in your System Prompt.
Prompt Writing Techniques
1. Provide Specific Details, Avoid Vague Instructions
The model cannot "guess" your true intent. Including specific background information, constraints, and expected output in the prompt can significantly improve result quality.
Negative Example:
Write an article for me.
Positive Example:
Please write a blog post targeted at technical team leaders on the topic of "How to promote the adoption of AI APIs within an enterprise."
Requirements:
- Word count: 800-1200 words
- Style: Professional but engaging, use analogies where appropriate
- Structure: Introduction -> Pain point analysis -> Solution (3 steps) -> Conclusion
- Include at least 1 real-world case study or scenario description
2. Use Delimiters to Separate Instructions from Content
When a prompt contains both operational instructions and content to be processed, use delimiters (such as """, ---, <tag>, etc.) to clearly separate them. This prevents the model from confusing instructions with input.
Please translate the following user review into English and determine the sentiment (positive/neutral/negative).
User review:
"""
This API endpoint has very fast response times, and the documentation is clearly written, although the error messages could be more user-friendly.
"""
Output format:
{"translation": "...", "sentiment": "..."}
3. Chain of Thought Prompting
For complex problems that require reasoning, computation, or analysis, guiding the model to "think step by step" can significantly improve accuracy.
Basic Usage: Add a guiding phrase at the end of the prompt.
Please analyze the performance bottlenecks of the following SQL query and provide optimization suggestions.
Before answering, please first analyze the query's execution logic step by step, then draw your conclusions.
Advanced Usage: Specify a reasoning framework.
Please analyze this market report following these steps:
1. Extract the core data points from the report
2. Identify correlations and trends among the data
3. Assess potential risks and opportunities
4. Based on the above analysis, provide 3 actionable recommendations
4. Few-shot Learning
By providing input-output examples, you help the model understand the response pattern and style you expect. Typically, 2-3 high-quality examples are sufficient for good results.
Please rewrite the following product descriptions into short social media copy style.
Example 1:
Input: These Bluetooth earphones feature active noise cancellation technology, up to 30 hours of battery life, and multi-device switching support.
Output: Your silent sanctuary on the commute! 30 hours of battery life, noise cancellation that shuts out the world, and seamless multi-device switching~
Example 2:
Input: This cloud server supports elastic scaling, pay-as-you-go billing, and provides 99.99% availability guarantee.
Output: No fear of traffic spikes during peak hours! Elastic pay-as-you-go scaling -- pay only for what you use, rock-solid at 99.99%.
Now please rewrite:
Input: Universe API offers a wide range of large language models with per-token pricing, starting from just $0.28 per million tokens.
Output:
5. Specify Output Format
Clearly tell the model the output format you expect, especially when structured data (JSON, tables, Markdown, etc.) is needed for downstream system processing.
Please analyze the key entities in the following text and output them in JSON array format.
Each entity should include three fields: name, type (person/location/organization/product), and description (a brief description).
Text: """
Jack Ma founded Alibaba Group in Hangzhou. Its products include Taobao, Tmall, and Alibaba Cloud, among others.
"""
Tip: If you have strict requirements for JSON format, it is recommended to add "Please ensure the output is valid JSON format, do not include Markdown code block markers" in the System Prompt to reduce parsing errors.
6. Control Output Length and Style
While models cannot precisely count words, you can roughly control the output length using descriptive instructions.
| Desired Effect | Recommended Phrasing |
|---|---|
| Short answer | "Please answer in one sentence" or "Summarize in 50 words or fewer" |
| Medium length | "Please explain in detail using 2-3 paragraphs" |
| Long text | "Please write a complete article of 800-1000 words" |
| List format | "Please list 5 key points in an ordered list" |
Complex Task Decomposition Strategies
Large language models perform best when handling single, well-defined tasks. When faced with complex requirements, breaking them down into multiple simple subtasks and executing them sequentially can significantly reduce error rates and improve output reliability.
Strategy 1: Multi-turn Conversation Decomposition
Break a complex requirement into multiple conversation turns, with each turn focused on a subtask.
# Turn 1: Intent Recognition
User input: "I'd like to check last month's sales data, and if there's a decline, help me analyze the reasons"
Please determine the user's core intent and output JSON: {"primary_intent": "...", "secondary_intent": "..."}
# Turn 2: Data Query (based on Turn 1 results)
Based on the intent "query last month's sales data," generate the corresponding SQL query statement.
# Turn 3: Root Cause Analysis (based on Turn 2 results)
The sales data shows a 12% month-over-month decline. Please analyze possible causes from the perspectives of market, product, and operations.
Strategy 2: Long Document Segmented Processing
When the document length exceeds the model's context window, adopt a stepwise summarization strategy:
Step 1: Per-chapter summary
-> Generate an independent summary for each chapter of the document
Step 2: Merge summaries
-> Combine all chapter summaries and distill the core viewpoints
Step 3: Final output
-> Generate a structured summary report based on the merged summaries
Strategy 3: Map-Reduce Pattern
Applicable to scenarios that require information integration across multiple documents:
Map phase: Extract key information (e.g., conclusions, data points, risk items) from each document separately
Reduce phase: Aggregate extraction results from all documents, deduplicate and merge, then generate a unified report
Advanced Techniques
Role Playing and Professional Perspective
Having the model think from the perspective of a specific professional role can yield more in-depth and specialized outputs.
You are a senior code reviewer with 15 years of Python development experience.
Please review the following code, focusing on:
1. Potential bugs and edge cases
2. Performance optimization opportunities
3. Code readability and maintainability
4. Security concerns
Output in the form of a review report, with each issue labeled by severity (Critical / Major / Minor).
Self-Verification and Error Correction
Guide the model to perform self-checking before producing output, reducing errors and omissions.
Please complete the following mathematical proof. After reaching a conclusion, go back and check whether each step of reasoning contains any logical gaps.
If errors are found, correct them and provide the revised final conclusion.
Template Prompts
For repetitive tasks, abstract the prompt into a template with variable placeholders for dynamic content, enabling easy batch invocation.
Please translate the following {source_language} text into {target_language}.
Requirements:
- Preserve the original paragraph structure
- Translate technical terms according to common usage in the {domain} field
- Tone and style: {tone}
Content to translate:
"""
{content}
"""
In actual invocation, replace variables such as {source_language} and {target_language} through code to reuse the same prompt template.
Parameter Tuning Suggestions
In addition to the prompt itself, API call parameters also affect output quality. Below are tuning recommendations for common parameters:
| Parameter | Function | Recommended Settings |
|---|---|---|
| temperature | Controls the randomness of the output. Higher values produce more diverse output; lower values produce more deterministic output. | Factual Q&A / code generation: 0.0-0.3; creative writing: 0.7-1.0; everyday conversation: 0.5-0.7 |
| top_p | Nucleus sampling; samples only from the highest-probability tokens. Adjust either this or temperature, not both. | Set low (e.g., 0.1) for precise output; set high (e.g., 0.9) for diversity |
| max_tokens | Limits the maximum number of tokens the model can output. | Set based on desired output length to avoid truncation or excessive verbosity |
| frequency_penalty | Reduces the repetition probability of tokens that have already appeared. | Increase (e.g., 0.5-1.0) when you need to avoid repetitive content |
| presence_penalty | Reduces the repetition probability of topics already discussed, encouraging the introduction of new topics. | Increase (e.g., 0.5-1.0) when diverse discussion is desired |
Note: Typically, you only need to adjust one of temperature and top_p. Adjusting both simultaneously may lead to unpredictable output behavior.
Common Problems & Pitfalls
| Problem | Possible Cause | Solution |
|---|---|---|
| Unstable model output; results vary significantly each time | temperature set too high, or prompt is not explicit enough | Lower the temperature; add specific constraints and examples |
| Model "hallucinations" (fabricating non-existent information) | Lack of knowledge boundary constraints | Explicitly state "please be honest when uncertain" in the System Prompt; use RAG to provide reliable knowledge sources |
| Output format does not match expectations | Format not specified or specification method not clear enough | Provide explicit format templates and example outputs; use JSON Mode to enforce structured output |
| Model "forgets" earlier content in long conversations | Context window limit exceeded | Periodically summarize conversation content; use segmented processing strategies; choose a model with a larger context window |
| Model refuses to execute a reasonable request | Triggered safety policies or role restrictions | Adjust wording to avoid ambiguity; explicitly authorize the model to handle such tasks in the System Prompt |
| Output is truncated and incomplete | max_tokens set too low | Increase the max_tokens parameter as appropriate; split long output tasks into multiple requests |
Prompt Template Quick Reference
Below are prompt templates for common application scenarios. Feel free to copy and modify them:
Text Classification
Please classify the following text.
Category options: {category_list}
Output only the category name, no explanation required.
Text: """{input_text}"""
Information Extraction
Extract all {entity_type} from the following text and output in JSON array format.
Each entity should include two fields: name and context (the context in which it appears).
Text: """{input_text}"""
Content Summary
Please generate a summary for the following content, keeping it within {word_count} words.
Requirements: Retain core viewpoints and key data; use concise language; do not add information not present in the original text.
Content: """{input_text}"""
Code Generation
Please write a function in {language} that implements the following functionality:
{function_description}
Requirements:
- Include complete type annotations and docstrings
- Handle common edge cases (e.g., empty input, invalid values)
- Include 2-3 usage examples
Multi-turn Dialogue System
# System Prompt
You are {assistant_name}, {role_description}.
# Conversation Specifications
- Each response should address only one core question
- If follow-up questions are needed, ask at most 1 question at a time
- Cite sources when referencing information
# Current Conversation Context
{conversation_history}
More Resources
- To learn about the capabilities and pricing of various models on Universe API, please refer to Product Introduction and Pricing.
- For complete API invocation methods and parameter documentation, please refer to the API Documentation.
- For common questions, please consult the FAQ or contact technical support.