Artificial Intelligence 14 min read

Guidelines and Best Practices for Prompt Engineering with Large Language Models

The guide outlines prompt‑engineering best practices for large language models, distinguishing base and instruction‑tuned LLMs, emphasizing clear, structured, step‑by‑step prompts, handling hallucinations, iterating through idea‑code‑data cycles, applying techniques to summarization, reasoning and expansion, managing token costs, and providing concrete OpenAI API examples.

Ximalaya Technology Team
Ximalaya Technology Team
Ximalaya Technology Team
Guidelines and Best Practices for Prompt Engineering with Large Language Models

1. LLM Types – The guide distinguishes between a Base LLM (trained on internet data, may give unrelated answers) and an instruction‑tuned LLM (fine‑tuned with prompts and RLHF, can follow user instructions such as “write a journalist‑style introduction about Alan Turing”.)

2. Two Main Prompt Principles – Clarity & specificity : use delimiters (commas, line breaks) and ask for structured output (e.g., JSON). Give the model time to think : break tasks into explicit steps (step 1: summarize, step 2: translate, step 3: extract names, step 4: return JSON) and let the model verify its own answer before responding.

3. Model Limitations – Outputs must be filtered for prohibited content; LLMs can hallucinate. A mitigation strategy is to require the model to cite sources from the provided text.

4. Iterative Development Workflow – For machine‑learning projects: generate an idea → implement code, collect data, train model → inspect outputs, perform error analysis → rethink and repeat. Emphasizes clear prompts, analysis of unexpected results, and continuous prompt refinement.

5. Application Scenarios – Summarization : condense long app reviews into 20‑character snippets for CEOs/CTOs. Reasoning : extract key information from government reports with length constraints. Expansion : turn short texts into longer articles or emails, e.g., brainstorming creative copy.

6. Token Economics – Pricing: $0.002 per 1 000 tokens. A token ≈ 4 characters in English, 2–2.5 characters in Chinese. Roughly 1 000 tokens ≈ 750 words. Typical question consumes 100–200 tokens; continuous conversation increases cost due to history tokens.

7. Online Practice – Demonstrates using the OpenAI API to generate ad copy for a podcast platform. Includes concrete prompt JSON and troubleshooting notes (trim whitespace, reduce batch size, adjust socket timeout). Example API request:

{
    "model": "gpt-3.5-turbo",
    "messages": [
        {
            "role": "user",
            "content": "你现在是一名SEM搜索投放关键词专家,我需要你根据输出给你的文字内容,帮助生产关键词,以使其简练、有重点、让人印象深刻。输出的关键词需要注意:1.能让我快速记住文字内容要点 2.避免对原有文字内容进行改写和添加,只能在原文基础上进行关键词提取 3.结果删除最大、第一、巅峰、优质、经典、精品、全新 4.结果删除免费、畅听、会员、完结、连载、完本、全本 5.结果以标准的Json格式返回 6.结果按照例子分组展示 7.结果字数≤5。例子:0.医林误案 1.大耍儿之两肋插刀 2.投资理财从入门到精通"
        }
    ]
}

Additional role‑based examples show how to set system , user , and assistant messages to maintain context across turns.

AILLMPrompt EngineeringAPI usagetoken cost
Ximalaya Technology Team
Written by

Ximalaya Technology Team

Official account of Ximalaya's technology team, sharing distilled technical experience and insights to grow together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.