Skip to content

4.2 Basic and Advanced Prompting Techniques

Sharpening the Tools for the Task: Mastering Basic and Advanced Prompt Engineering Techniques

Section titled “Sharpening the Tools for the Task: Mastering Basic and Advanced Prompt Engineering Techniques”

Having understood the crucial role of Prompt Engineering in effectively utilizing Large Language Models (LLMs) (see Section 4.1), the next step is to master specific techniques, translating abstract principles into actionable practices. Just as lawyers need proficiency in different legal research methods or trial advocacy skills, interacting efficiently and precisely with LLMs requires mastering a systematic methodology and practical “trade secrets.”

Large Language Models are essentially systems based on pattern matching and probability prediction from vast training data; they lack genuine understanding, common sense, or intent. Therefore, the “Prompt” we issue acts like the instructions and context we provide when communicating with an extremely knowledgeable but sometimes overly “literal” or “passive” apprentice. The quality of the prompt directly dictates whether this “super apprentice” can accurately grasp our intent and deliver a compliant, valuable response.

This section systematically introduces a series of prompt engineering techniques, ranging from basic to advanced, designed to help you better construct prompts and guide LLMs to unleash their full potential. We will supplement these with examples relevant to legal scenarios, assisting you in gradually enhancing your ability to command LLMs, turning this powerful “intelligent assistant” into a truly useful tool for improving quality and efficiency in legal work.

I. Basic Prompting Techniques: Laying the Foundation for AI Communication

Section titled “I. Basic Prompting Techniques: Laying the Foundation for AI Communication”

These are the cornerstone principles and fundamental techniques for constructing any effective prompt. While seemingly simple and intuitive, they are prerequisites for successfully employing more advanced strategies and apply to nearly all interactions with LLMs. Mastering and flexibly applying these basics is the first step towards clear and effective communication with AI.

1. Clear and Specific Instructions: Avoid Ambiguity

Section titled “1. Clear and Specific Instructions: Avoid Ambiguity”
  • Principle: LLMs lack human intuition and background knowledge; they process instructions literally. Therefore, using concise, direct, unambiguous language to tell the model exactly what specific task you want it to perform is crucial. Vague, overly broad, or open-ended questions make it difficult for the AI to determine the objective, leading to outputs that deviate from expectations or are too generalized to be useful.
  • Techniques:
    • Use Action Verbs: Prefer imperative sentences starting with clear action verbs that pinpoint the task’s core. E.g., “Summarize” the key points of the judgment below, “List” all defined terms in this contract, “Identify” and “extract” key deadlines from the email, “Draft” an initial version of a demand letter regarding issue XX, “Compare and contrast” these two statutes regarding provision YY, “Explain” the elements of the legal concept “apparent authority,” “Translate” this English testimony into [Language].
    • Decompose Complex Tasks: If a task involves multiple steps or objectives, try breaking it down into smaller, simpler sub-instructions with clearer goals. These can be issued sequentially in different interaction turns or clearly listed using numbers or bullet points within a single prompt to guide the model sequentially.
    • Define Scope and Object: Clearly specify the target object of the instruction (analyze the contract in Appendix A, or process the text provided below?) and the desired scope of processing (analyze the entire document, or only specific sections/clauses/time periods? cover all details, or focus on core points?).
  • Example Comparison:
    • Vague Instruction (Ineffective): “What about this contract?” (AI: ??? Where should I start?)
    • Clear Instruction (More Effective): “Identify all clauses in the following ‘Commercial Lease Agreement’ (text below) concerning rent payment methods, payment deadlines, and liability for late payment. Please list the specific clause numbers and their core content points in a bulleted list format.”
    • Vague Instruction (Ineffective): “Analyze this case.” (AI: Analyze what aspect? Facts? Law? Risk? For whom?)
    • Clear Instruction (More Effective): “Analyze the following labor dispute case summary. Identify the main potential legal issues in dispute (e.g., legality of termination, calculation of severance pay), and list the key factual grounds supporting the plaintiff’s claims and the defendant’s defenses (if mentioned).“

2. Provide Sufficient & Relevant Context: Keep the AI “Informed”

Section titled “2. Provide Sufficient & Relevant Context: Keep the AI “Informed””
  • Principle: The quality of an LLM’s response heavily depends on the background information (context) it can access and understand while processing the request. Just like collaborating with human colleagues, providing necessary background, relevant knowledge, or preconditions helps the model better understand your true intent, the specific task requirements, and the particular basis needed for accurate judgment or relevant content generation. Lacking necessary context forces the AI to rely on its vast but generic pre-trained knowledge base for “guessing,” likely resulting in outputs disconnected from your specific needs.
  • Techniques:
    • Inject Key Information: Directly include relevant background information necessary for the current task within your prompt. This might include a brief case fact summary, an overview of the transaction background for a contract, key excerpts of the specific legal framework or internal company policy to be followed, or a summary of key points from previous turns in a multi-turn conversation.

    • Clearly Specify Input Data: If the task involves processing specific text, data, or files, clearly include it within the prompt (using delimiters, discussed below) or specify its source (e.g., “Please analyze the judgment text in Appendix A,” “Based on the client email content provided below…”).

    • Set Premises or Constraints: If your task operates under specific preconditions, assumptions, or constraints, clearly state them in the prompt. E.g., “Assuming the contract law of [Jurisdiction] applies to this case…”, “When analyzing, please consider only the contract text itself, disregarding actual performance for now…”, “Ensure the generated clauses maximize our client’s interests as [Party A/Party B] while maintaining basic fairness…”.

  • Example Comparison:
    • Lacking Context: “Draft an intellectual property clause for a software development contract.” (AI: For whom? What software? What scenario? Payment terms?… Too little info, can only offer a generic template.)
    • Sufficient Context Provided: “Our company (Party A, an online education platform) is commissioning Party B (a software outsourcing firm) to custom develop an online examination system. Please draft the Intellectual Property (IP) ownership clause for this software development agreement. The guiding principle is: 1. Party A pays all development costs, thus full IP rights in the final examination system software (including source code, object code, related documentation) shall belong to Party A; 2. Party B’s pre-existing underlying technology or libraries used in development (needs clear definition/listing) shall remain Party B’s property, but Party B shall grant Party A a perpetual, royalty-free, irrevocable, worldwide license to use them as necessary for Party A to operate and maintain the system; 3. Party B shall not use any code or deliverables developed for this project for other projects or third parties without Party A’s prior written consent. Please ensure the wording is precise and rights are clearly defined.”

3. Specify Desired Output Format: Make Results “Tidy” and Usable

Section titled “3. Specify Desired Output Format: Make Results “Tidy” and Usable”
  • Principle: Don’t assume the AI can “read your mind” and automatically present results in your preferred format. Clearly informing the model about the specific form, structure, layout, or style you expect for the output can greatly enhance the usability of the result, making it easier for you to process, cite, integrate, or present to others. Specifying format requirements also helps constrain the model’s output, keeping it focused on the core content.
  • Techniques:
    • Directly Request Specific Formats: Explicitly ask for bullet points (e.g., “Please list… using bullet points”), numbered lists (e.g., “List… in order of importance”), tables (specify column names and general content, e.g., “Summarize… in a table with columns for ‘Clause Number,’ ‘Core Content,’ ‘Risk Level’”), JSON format (common for programmatic processing), XML format, etc.
    • Limit Output Length or Scope: Provide approximate word count limits (e.g., “Summarize the following content within 300 words”), number of points limits (e.g., “Identify no more than the 5 most significant legal risks”), paragraph limits, or overall length constraints (e.g., “Generate an initial draft memo of no more than two pages”).
    • Define Structure and Headings: Request the model to use specific headings, subheadings, section numbers, or other structural elements to organize the content for better readability and structure.
    • Specify Language Style: Clearly state the desired language style, e.g., “Use formal, professional legal terminology,” “Use simple, plain language, avoiding jargon,” “Present the statement in an objective, neutral tone.”
  • Example:
    • “Please rewrite the following complex legal reasoning from a judgment (text below) into a summary easily understandable by a non-legal client. Requirements: 1. Total word count under 250 words; 2. Use simple, clear language, avoid technical terms; 3. Focus on explaining which core claims the court upheld or dismissed, and the key reasons why; 4. Use clear paragraph separation.”
    • “Please extract all provisions related to the ‘Valuation Adjustment Mechanism’ (VAM) from this ‘Investment Agreement’ (Appendix C). Organize the results into a table with the following four columns: ‘Clause Number’, ‘Party Subject to Performance Target’, ‘Description of Performance Target’, ‘Trigger Condition and Adjustment/Compensation Method’.“

4. Leverage Role Prompting / Persona Prompting: Grant AI a “Professional Perspective”

Section titled “4. Leverage Role Prompting / Persona Prompting: Grant AI a “Professional Perspective””
  • Principle: Explicitly instructing the model to adopt a specific role, identity, or persona—one with a particular professional background, experience level, or even stance—can very effectively guide the model to adjust its perspective, choose appropriate terminology, gauge the right level of detail, adopt a specific language style, and overall tone. Like setting a role for an actor, it helps the model’s “performance” become more immersive, aligning the output more closely with your specific needs and target audience.
  • Techniques:
    • Use clear phrasing like “Assume you are a…,” “Answer as a…,” “Acting as a…, please…,” “Your role is…, complete the following task,” “You are a [Role], please…” to set the persona.
    • Make the persona as specific as possible: Not just “lawyer,” but “a senior lawyer with over 20 years of experience specializing in cross-border M&A in [Jurisdiction]”; not just “judge,” but “a trial court judge experienced in handling intellectual property cases”; not just “consultant,” but “a consultant specializing in providing financing legal services to tech startups, particularly skilled at explaining complex issues concisely.”
    • Combine persona setting with task instructions, format requirements, and style requirements for more powerful composite prompts.
  • Example:
    • Assume you are a highly meticulous securities lawyer preparing the risk factors section of a prospectus for a company planning an IPO on the [Specific Stock Exchange]. Please review the following preliminary description of ‘technology dependence risk’ provided by the business department (text attached). Identify any inaccurate statements, insufficient risk disclosures, or issues that might raise concerns with regulators. Provide specific revision suggestions (please explain the reasons for changes).” (Persona + Task + Context + Specific Output Request)
    • Act as a patient volunteer at a legal aid clinic. Explain to a client involved in a civil lawsuit for the first time, who has no prior legal knowledge (assume limited formal education), what preparations they need to make after receiving a court summons, what the general court hearing process looks like, and what their basic litigation rights are. Please use the simplest, most colloquial, easiest-to-understand language possible, and avoid any wording that might cause them alarm or stress.” (Persona + Task + Audience Profile + Language Style Requirement)
    • As an experienced external counsel representing a large multinational corporation (defendant) in product liability litigation, please analyze the plaintiff’s expert report (summary attached). Identify potential logical flaws, methodological weaknesses, questionable data points, or inconsistencies with industry practices or scientific common sense. List key lines of questioning for cross-examining this expert in court (please list at least 5).” (Persona + Task + Context + Specific Output Format Request)

5. Use Delimiters to Clearly Define Input Sections: Avoid Information “Confusion”

Section titled “5. Use Delimiters to Clearly Define Input Sections: Avoid Information “Confusion””
  • Principle: When your prompt contains multiple distinct components—such as instructional text, a large block of context text for processing (contract clauses, judgment excerpts), specific questions, or even few-shot examples—mixing these parts without clear separation can confuse the model. It might struggle to distinguish instructions from data, or data from questions. Using clear, consistent delimiters to explicitly partition and demarcate these different input sections, much like using headings or paragraph breaks in a document, helps the model parse your prompt structure more accurately, understand the intent of each part, and thus avoid information confusion and instruction misinterpretation.

  • Techniques:

    • Choose a delimiter that is clear and easily recognizable by the model, and use it consistently throughout the prompt. Common delimiters include:
      • Triple quotes: """ [Content] """
      • Triple backticks: [Content] (Often used for code, but works for text too)
      • XML tags: <tag_name> [Content] </tag_name> (e.g., <instruction></instruction>, <context></context>, <question></question>)
      • Simple separators: --- or ***
      • Explicit labels/headings: E.g., using “[Instruction]”, “[Text to Process]”, “[My Question Is]”.
    • Clearly enclose or separate instructions, the main text to process, examples, specific questions, etc., using your chosen delimiter.
  • Example:

    [Role Setting]
    Assume you are a lawyer specializing in corporate governance.
    [Task Instruction]
    Please carefully read and analyze the following excerpt from the Articles of Association. Identify specific provisions directly related to the "duty of loyalty and duty of care" of directors, and assess whether these provisions generally comply with the fundamental requirements of the [Applicable Jurisdiction]'s Company Law.
    [Text to Process: Excerpt from Articles of Association]
    """
    Chapter 5: Board of Directors
    Article 120: Directors shall comply with laws, administrative regulations, and these Articles, and owe duties of loyalty and care to the company.
    Article 121: Directors shall not use their position to accept bribes or other illegal income, nor shall they embezzle company property.
    ... [Other articles omitted] ...
    Article 135: If a director violates laws, administrative regulations, or these Articles when performing duties, causing losses to the company, they shall be liable for compensation.
    """
    [Specific Requirements]
    Please structure your analysis output as follows:
    1. **Relevant Articles Identification**: List the article numbers in the excerpt that directly address directors' duties of loyalty and care.
    2. **Core Content Summary**: Briefly summarize the main content stipulated by these articles.
    3. **Compliance Assessment**: Briefly evaluate whether these articles generally align with the principles of director duties and liabilities under the Company Law, noting any apparent deficiencies or areas of concern.
    [Begin Analysis]

6. Provide Appropriate Examples (Few-shot Prompting): Let “Samples” Speak

Section titled “6. Provide Appropriate Examples (Few-shot Prompting): Let “Samples” Speak”
  • Principle: Sometimes, describing a complex task or desired output format using only abstract textual instructions might be insufficient or prone to ambiguity. Especially for tasks requiring the model to follow a specific, uncommon output format, perform complex text transformations (like style transfer or specific information extraction patterns), or mimic a unique writing style, “showing is better than telling” is often more effective. Providing one or more complete “input-desired output” example pairs in the prompt, like showing the model “samples” or “templates,” can very effectively and concretely demonstrate exactly what you want it to do and to what standard.

  • Technical Background: LLMs possess powerful In-context Learning abilities. When they see examples in the prompt, they try to infer patterns and rules from them and apply these learned patterns to process the new task you subsequently provide.

  • Techniques:

    • Example Format: Typically use pairs like Input: [Example Input Text] followed by Output: [Corresponding Desired Output Text].
    • Number of Examples (Few-shot): Usually, providing 1 to 3 high-quality, representative examples is sufficient to guide the model (Few-shot Prompting). Providing 0 examples (relying solely on instructions) is Zero-shot Prompting. Providing many examples (tens, hundreds, or more) is closer to model Fine-tuning, which involves a different technical process.
    • Quality Over Quantity: The provided examples must be accurate, well-formatted, and highly relevant to your target task. Incorrect, low-quality, or irrelevant examples can severely mislead the model, leading to worse results. Crafting good examples requires careful thought.
    • Connecting Examples to New Task: After providing the examples, immediately present the new input you actually want the model to process, often preceded by a clear instruction like, “Now, following the pattern in the examples above, process the following new input:”.
  • Example (Simplifying complex legal risk descriptions into a fixed format):

    [Task]: Simplify the following legal risk descriptions into a structured output containing "Risk Area," "Risk Summary," and "Preliminary Rating."
    [Example 1]
    Input: "Upon review, we found ambiguities in the IP ownership clauses within several key supplier contracts of the target company, particularly regarding the allocation of rights in jointly developed deliverables. This could lead to potential ownership disputes in the future, especially upon termination of the partnership or divestiture of technology. The risk is considered high."
    Output:
    {
    "Risk Area": "Intellectual Property / Contract",
    "Risk Summary": "Ambiguous IP ownership (esp. joint development) in key supplier contracts may cause future disputes.",
    "Preliminary Rating": "High"
    }
    [Example 2]
    Input: "A preliminary check of the company website's privacy policy revealed that its disclosures regarding the purpose, manner, and scope of personal information processing lack specificity and comprehensiveness. Furthermore, it fails to provide a clear mechanism for users to withdraw consent. This may not fully comply with the latest requirements of the Personal Information Protection Law, presenting certain compliance risks. Revision is recommended soon."
    Output:
    {
    "Risk Area": "Data Compliance / Privacy",
    "Risk Summary": "Website privacy policy lacks specificity in disclosures and clear consent withdrawal mechanism, potentially non-compliant with PIPL.",
    "Preliminary Rating": "Medium"
    }
    [New Task]
    Now, following the format and style of the examples above, process the following new risk description:
    Input: "Analysis of the company's standard employment contract template indicates that the wording regarding overtime pay calculation standards is inconsistent with recent local judicial interpretations. Strict adherence to the template could expose the company to the risk of employee arbitration claims demanding back pay for overtime and economic compensation."
    Output: [Let model generate structured JSON output based on the pattern]

II. Advanced Prompting Techniques: Unlocking Deeper LLM Potential

Section titled “II. Advanced Prompting Techniques: Unlocking Deeper LLM Potential”

When basic techniques are insufficient for more complex tasks, or when you want to further enhance the quality, reliability, logic, and controllability of the output, you can experiment with the following more advanced prompting strategies. These often require a deeper understanding of how LLMs work and may involve more experimentation and iteration.

7. Chain-of-Thought (CoT) Prompting: Guiding AI to “Think Step by Step”

Section titled “7. Chain-of-Thought (CoT) Prompting: Guiding AI to “Think Step by Step””
  • Principle: Many complex legal problems or tasks (e.g., legal relationship analysis requiring multi-step logical deduction, damage calculation involving multiple variables and rules, fact determination needing synthesis of multiple evidence sources) are prone to errors if the LLM is asked directly for the final “answer” or “conclusion.” It might tend to provide a superficially plausible answer based on common patterns in its training data, but with an incomplete or unsound internal logical chain. Chain-of-Thought (CoT) prompting’s core idea is not to ask directly for the final answer, but instead, through explicit instruction or examples in the prompt, guide the model to first “explicitly” output its intermediate steps, reasoning process, analytical logic, or thought process before giving the final conclusion. This is like asking a student to “show their work” when solving a complex math problem.
  • Core Effect: Extensive research and practice have shown that this method of “making the model think aloud” or “showing its work” can significantly improve the accuracy and reliability of LLMs on tasks requiring complex reasoning, mathematical calculation, common sense judgment, multi-step planning, and logical analysis. It forces the model to slow down its “thinking,” process the problem more structurally and methodically, and also allows users to inspect its reasoning process for plausibility, logical gaps, or factual errors.
  • Techniques:
    • Instruction-based CoT (Zero-shot CoT): Simply append instructional phrases like “Think step-by-step and explain your reasoning.”, “Let’s break this problem down step by step.”, “Before giving the final answer, please list your analysis steps and the reasoning for each step.”, or “Let’s think step by step.” to the end of the prompt.
    • Example-based CoT (Few-shot CoT): When providing few-shot examples, crucially include the detailed, step-by-step thinking process or reasoning chain within the “Output” part of the example, not just the final answer. Seeing these examples, the model learns to mimic this “think first, then answer” pattern for your new problem. This approach is generally more effective than zero-shot CoT, especially for very complex tasks.
  • Example (Complex Legal Application Analysis):
    • Basic Prompt (Might give direct answer, prone to error): “Case Facts: [Describe complex case facts involving product liability, consumer rights, possibly validity of standard terms]. Question: Should the seller be liable for compensation to the consumer?”
    • Example-based CoT Prompt (Guides detailed analysis, improves accuracy):
      [Task]: Analyze the following case facts, determine if the seller should be liable for compensation, and provide detailed reasoning.
      [Example]
      Input: [Describe simple breach of contract case facts]
      Output:
      Thought Process:
      1. Was a valid contract formed? [Yes/No, reason...]
      2. Did the seller commit a breach? [Yes/No, specific act..., violated which clause or legal duty...]
      3. Are there any defenses or exemptions? [Yes/No, reason...]
      4. Did the consumer suffer damages? Is there causation between the breach and damages? [Yes/No, reason...]
      5. Based on the above analysis, should the seller be liable?
      Conclusion: The seller should/should not be liable for compensation, mainly because...
      [New Task]
      Now, following the **thought process pattern** in the example above, analyze the following new case facts and provide your conclusion with detailed reasoning:
      Input: [Describe the complex case facts involving product liability, consumer rights, standard terms mentioned earlier]
      Output: [Let model generate response including detailed thinking steps and final conclusion]
      (By forcing the model to explicitly show its step-by-step analysis logic in the output, you can significantly improve the logical rigor and reliability of its handling of complex legal issues, and also facilitate human review of its reasoning process.)

8. Self-Critique / Self-Correction / Self-Refinement: Prompting AI to “Reflect”

Section titled “8. Self-Critique / Self-Correction / Self-Refinement: Prompting AI to “Reflect””
  • Principle: Although LLMs don’t “reflect” like humans, they have learned vast patterns related to evaluating, critiquing, and revising text from their training data. They thus possess some capability (albeit limited and pattern-based) to assess and improve their own or others’ output. We can leverage this by designing a multi-turn interaction strategy: first, have the model generate an initial, potentially imperfect response or draft for a task. Then, in the next turn, explicitly instruct it to act as a “critic” or “editor,” reviewing its own just-generated draft to actively identify potential flaws (e.g., factual errors, logical contradictions, insufficient reasoning, unclear phrasing, missed key points, improper formatting). Based on this critique, it should then generate a revised, improved version. This approach of “having the AI check its own homework” or “debating with itself” can sometimes effectively enhance the quality, accuracy, rigor, and reliability of the final output.
  • Techniques: After the model provides an initial response, follow up with prompts like:
    • “Please carefully review and evaluate the response you just provided. Are there any factual errors, omissions, or logical inconsistencies? Please identify these issues clearly and provide a corrected version.”
    • “In what aspects could the previous analysis be further strengthened or improved? For example, is the reasoning sufficiently supported? Were all relevant legal risk factors considered? Is the language professional and precise enough? Based on these reflections, generate an optimized, higher-quality version.”
    • Assume you are an extremely experienced senior partner lawyer known for meticulous attention to detail, reviewing this draft memo submitted by a junior lawyer (the role you just played). Using a critical eye, identify all instances where the writing is not rigorous enough, potentially exposes vulnerabilities to opposing arguments, or fails to adequately protect the client’s interests. Please directly provide the revised, improved wording.”
    • Combine with CoT: First, have the model generate a draft along with its detailed thought process (CoT). Then, ask it to review the final draft based on the thought process it wrote down, checking for consistency, logical gaps, or insufficient justification, and make corrections.
  • Example (Contract Clause Drafting & Iterative Refinement):
    • First Prompt (Request Draft): “For a technical service agreement, please draft a core clause regarding the ‘Service Level Agreement (SLA),’ including service availability commitment (target 99.9%), fault response time (respond within 4 hours), issue resolution time (differentiated by priority, e.g., high priority resolved within 8 hours), and remedies for non-compliance (e.g., proportional reduction of monthly service fee).”
    • Model generates initial draft SLA clause…
    • Second Prompt (Request Self-Critique & Improvement): “Act as a lawyer representing the client (service recipient) who is extremely risk-averse. Please review the SLA clause you just drafted. Identify all wording that might be unfavorable to the client, insufficiently clear, or likely to cause disputes. For example: Is the calculation method for ‘service availability’ clearly defined? Are the definitions of ‘fault’ and ‘issue priority’ clear and fair to the client? Are the remedies sufficiently robust and easy to enforce? Point out these potential issues and provide a revised version that better protects the client’s interests.”

9. Strategies for Handling Long Texts: Chunking, Sliding Window, Summarization & Synthesis: Divide and Conquer, Aggregate Results

Section titled “9. Strategies for Handling Long Texts: Chunking, Sliding Window, Summarization & Synthesis: Divide and Conquer, Aggregate Results”
  • Principle: Most current LLMs have a Context Window Limit, meaning the total length of text they can effectively process at once (including user input, model output, and multi-turn history) is finite. Although this limit is constantly expanding with technological advancements (e.g., models like Claude 3.5 Sonnet, GPT-4o, Gemini 1.5 Pro support hundreds of thousands or even millions of tokens), dealing with extremely lengthy legal documents (e.g., analyzing an M&A due diligence report with hundreds of attachments totaling thousands of pages; reviewing millions of emails and documents in e-Discovery; comprehensively summarizing a complex law with all its accompanying regulations and interpretations) can still lead to performance degradation (the “needle in a haystack” problem), excessive costs, or exceeding limits even for the most advanced models. Therefore, mastering strategies to “divide and conquer” long texts by processing them in chunks, and then “aggregating” the results remains crucial.

  • Techniques:

    • Meaningful Chunking: The core is to split the original long text into multiple meaningful, manageable chunks (length usually significantly smaller than the model’s context limit to allow room for processing). Split points should ideally be at natural semantic or structural boundaries:
      • By paragraph.
      • By document sections, article numbers.
      • By specific topic sentences or keywords.
      • Goal: Maintain semantic coherence and completeness within each chunk as much as possible. Smart chunking libraries (e.g., in LangChain, LlamaIndex) can help.
    • Overlapping Chunks: To ensure smooth context transition between adjacent chunks and avoid cutting off key information at split points, allow some overlap between consecutive chunks (e.g., the beginning of the next chunk includes the last few dozen or hundred words of the previous chunk).
    • Sliding Window: Another common approach for long sequences, where the model processes content within a moving window that slides across the text.
    • Stepwise Processing & Result Integration Strategy:
      1. Design Prompt for Single Chunk: First, create a clear prompt applicable to each individual chunk. E.g., “Summarize the core content of this chunk,” “Identify all sentences in this chunk mentioning ‘liability for breach’ and list them,” “Determine if the content of this chunk relates to ‘intellectual property licensing,’ if so, extract key license terms.”
      2. Iteratively Process All Chunks: Automate (usually via simple scripts or frameworks) the application of this “single-chunk prompt” to every chunk derived from the original long text. Collect and store the model’s output for each chunk (e.g., store summaries, extracted clauses, relevance judgments for each chunk).
      3. Final Aggregation & Synthesis: After processing all chunks, design one or more separate prompts to have the model synthesize, refine, analyze, compare, or integrate the intermediate results collected from all chunks. E.g., “I will provide a list of key point summaries extracted from various sections of a long judgment. Please use these points to write a complete, coherent summary report of the judgment, covering the main issues, court’s findings, core reasoning, and final outcome, keeping the total word count under 1000 words. Here is the list of key points: [paste all chunk summaries]”.
    • Leveraging Long-Context Models & Caveats: If feasible and cost-effective, prioritize models that natively support very long context windows. They can handle extremely long documents (or at least their core parts) directly, greatly simplifying or even eliminating complex chunking processes. However, even with long-context models, beware of the “Lost in the Middle” problem, where models might pay more attention to information at the beginning and end of the input, potentially neglecting or poorly recalling information in the middle. Thus, even with long context, critical information located mid-document might need special emphasis in the prompt (e.g., repeating it near the start/end) to ensure adequate attention.
  • Example (Processing case files with multiple witness transcripts to find and compare descriptions of a key event):

    1. Chunking: Treat each individual witness transcript as a “chunk” (assuming single transcripts fit within the context window).
    2. Single-Chunk Processing Prompt: Design: “Please carefully read the following transcript of [Witness Name]‘s testimony. Identify all descriptions related to [a specific key event, e.g., ‘the discussion in Conference Room XX on the afternoon of March 15, 2024’]. If found, please extract the relevant complete sentences or paragraphs and note their page number or approximate location in the transcript. If no relevant description is found, respond ‘Not mentioned’.”
    3. Iterative Processing: Apply this prompt to each witness transcript, collecting all extracted description snippets about the event and their sources.
    4. Final Integration & Comparison Prompt: “I will provide all description snippets regarding [key event] extracted from multiple witness testimonies. Act as a meticulous criminal investigator or litigation attorney and perform the following tasks: a. Summarized List: Clearly list all description snippets, organized by witness name and source. b. Identify Consistency: Find points of content that are corroborated or generally consistent across different testimonies. c. Identify Contradictions: Find points where descriptions from different witnesses are clearly contradictory or inconsistent. d. Raise Questions: Based on the comparison, formulate potential points of doubt or questions that need further verification or should be key focus areas during cross-examination. Here is the list of description snippets: [paste all collected snippets]“

10. Negative Prompting: Defining “What Not to Do,” Setting Boundaries

Section titled “10. Negative Prompting: Defining “What Not to Do,” Setting Boundaries”
  • Principle: In many cases, positive instructions telling the model what to do might not be precise enough, or the model might produce undesired side effects while fulfilling the task (e.g., generating information types we don’t need, using a style we want to avoid, touching on sensitive topics). In such situations, explicitly telling the model “what not to do,” “what content to avoid,” “which possibilities to exclude,” or “ensuring the output is not of a certain type”—i.e., using Negative Prompting—can serve as a useful complement to positive instructions. It helps further constrain the model’s behavior boundaries, making the output better align with our refined requirements.

  • Techniques:

    • Use clear negative or exclusionary words and phrases in the prompt. E.g., “Do not include any discussion of price,” “Avoid using overly colloquial or informal language,” “When analyzing risks, please exclude those that are merely theoretical possibilities without actual supporting evidence,” “Ensure the generated summary is not a simple copy-paste of the original text, but paraphrased in your own words,” “Refrain from providing any specific investment advice in the response.”
    • In some specialized image generation AI tools (like Stable Diffusion Web UIs), there is often a dedicated “Negative Prompt” input box. Users can specifically list elements, attributes, styles, or quality issues they don’t want in the final image (e.g., inputting “low quality, blurry, extra fingers, distorted face, text, signature, watermark, cartoon style, horror”) to guide the model towards more desirable, higher-quality outputs.
  • Example:

    • “Based on the following email exchange records provided (emails attached), objectively summarize the main points of communication and the respective positions of both parties regarding the contract performance dispute. When summarizing, please strictly adhere to the following requirements: 1. Do not make any subjective judgments or implications about which party is right or wrong; 2. Do not include any speculation or assumptions beyond the content of the emails; 3. Avoid using any emotionally charged or inflammatory language; 4. Only present the views and claims explicitly expressed by the parties.”
    • “Draft core confidentiality clauses for an employee agreement for a startup company. When defining ‘Confidential Information,’ ensure the scope is broad enough to protect the company’s core interests, but avoid defining it so broadly that it might be deemed invalid due to unconscionability. Specifically, do not include general knowledge and skills the employee possessed before joining, or information already publicly available in the industry, within the definition of confidential information.”
    • (Assuming AI analyzing contract risk) “Identify all clauses in this lease agreement potentially unfavorable to the ‘Lessee.’ When listing risks, please exclude those that are merely mandatory legal requirements (like timely rent payment) or standard, fair industry practices. Focus only on special or unusual provisions that significantly increase the lessee’s liability, restrict the lessee’s rights, or present major uncertainties.”

11. Adjusting Decoding Parameters: Temperature & Top-p/Top-k (Temperature & Sampling Parameters): Balancing “Creativity” and “Precision”

Section titled “11. Adjusting Decoding Parameters: Temperature & Top-p/Top-k (Temperature & Sampling Parameters): Balancing “Creativity” and “Precision””

(Note: This technique usually applies only when calling models via API, or in certain local deployment interfaces or specific applications that allow advanced settings. Most public web chat interfaces do not offer direct control over these parameters.)

  • Principle: When generating text, LLMs don’t just look up the single “correct” next word. At each step, based on the preceding text (context), they calculate a probability distribution over all possible words in their vocabulary. Instead of always picking the highest probability word (“Greedy Sampling,” which leads to monotonous output), they perform random Sampling based on this distribution to choose the next word. Temperature and Top-p (Nucleus Sampling) / Top-k Sampling are key Decoding Parameters used to control the degree of randomness in this sampling process—balancing “creativity” versus “determinism.” Understanding and appropriately adjusting these parameters allows for finer control over the model’s output style and content for different tasks.

    • Temperature:
      • Role: Acts like a thermostat, adjusting the “shape” of the original probability distribution.
      • Low Temperature (e.g., 0.1 to 0.5, closer to 0): “Sharpens” the distribution, making high-probability words even more likely and further suppressing low-probability ones. The model favors common, predictable, “safe” words. Output becomes more deterministic, consistent, conservative, focused, but potentially bland, repetitive, or rigid.
      • High Temperature (e.g., 0.8 to 1.5 or higher, >1 flattens distribution): “Smoothes” the distribution, reducing probability differences, giving lower-probability words a better chance. The model is more likely to deviate from norms, choosing less common, perhaps surprising words. Output becomes more random, diverse, “creative,” interesting, or unexpected, but also potentially less predictable, more prone to topic drift, logically weaker, or even nonsensical.
      • Temperature 0: Theoretically corresponds to greedy sampling.
    • Top-p (Nucleus Sampling):
      • Role: Sets a cumulative probability threshold p (e.g., p=0.9). Before sampling, words are ranked by probability. The model selects the smallest set of top words whose cumulative probability just exceeds or equals p (this set is the “nucleus”). Sampling occurs only within this nucleus, based on relative probabilities; all words outside the nucleus are excluded.
      • Effect: Smaller p (e.g., 0.5) means a smaller nucleus, very limited candidates, resulting in more conservative, focused output. Larger p (e.g., 0.95) means a larger nucleus, more candidates, leading to more diverse output. Top-p is considered a good balancing strategy, allowing some randomness while effectively avoiding completely irrelevant or absurd output by excluding the long tail of low-probability words, often better than just increasing temperature.
    • Top-k Sampling:
      • Role: Simpler approach: sets an integer k (e.g., k=50). The model considers only the top k most probable words at each step and samples from within this set based on their relative probabilities, ignoring all words ranked below k.
      • Effect: Smaller k means fewer candidates, more conservative, deterministic output. Larger k means more candidates, more diverse output.
  • Application Strategy in Legal Scenarios:

    • Prioritizing Rigor and Accuracy: For tasks demanding high factual accuracy, logical rigor, strict adherence to specific formats, or precise use of legal terminology—such as interpreting legal clauses, summarizing case facts, drafting segments for court filings (under strict review), or performing rule-based compliance checks—use lower temperature values (e.g., try 0.2 - 0.5) possibly combined with smaller Top-p values (e.g., 0.7 - 0.9) or moderate Top-k values (e.g., 40-60). This yields more stable, reliable output closer to facts and rules, minimizing risks from “creativity.”
    • Needing Creativity and Diversity: For tasks aimed at sparking ideas, brainstorming, exploring possibilities, or generating content requiring variation and appeal—such as developing multiple arguments for a debate point, drafting different styles of client communication emails, creating fictional case scenarios for training or public education, or exploring initial legal research directions—you can increase temperature slightly (e.g., try 0.7 - 1.0) perhaps with larger Top-p values (e.g., 0.92 - 0.98) or larger Top-k values. This encourages more diverse, potentially insightful ideas or text. However, be more vigilant about potential topic drift or logical issues.
  • Practical Advice:

    • Understand Defaults: Know the default settings for these parameters on your platform or API; they usually represent a balanced starting point for general use.
    • Adjust Incrementally & Experiment: When tuning, start from defaults and make small adjustments (e.g., temperature +/- 0.1 or 0.2), then observe the changes in output. There’s no single “best” combination; finding the optimal setting for your specific task and model requires iterative experimentation.
    • Record Effective Combinations: Once you find parameter settings that work well for certain tasks, document them along with the corresponding prompt for future reuse.

Conclusion: Practice Makes Perfect, Iteration is Key, Experience Accumulates

Section titled “Conclusion: Practice Makes Perfect, Iteration is Key, Experience Accumulates”

Mastering the various techniques of prompt engineering is not a one-off theoretical study but more akin to learning a “craft” that requires continuous exploration, realization, and refinement through practice. There are no absolutely “correct” or “universal” prompt templates, only strategies that are relatively more effective, precise, and reliable for a specific application scenario, targeting a particular AI model, to achieve a specific goal. To truly enhance your prompt engineering skills and become an effective “AI conductor,” the following are crucial:

  • Start by Imitating Good Examples: The most effective starting point for beginners is to learn from and imitate excellent prompt templates provided by experienced users or reliable sources (like later chapters of this encyclopedia, official documentation, high-quality community shares). Analyze the design thinking behind these templates: How do they apply basic techniques (clear instructions, sufficient context, specified format)? Under what circumstances do they introduce advanced techniques (role-playing, few-shot, CoT)? Imitation and understanding help quickly build an intuition for effective prompt structures.
  • Iterate Through Trial and Error in Practice: Theory is foundational, but true mastery comes from extensive practice. Consciously apply the learned prompting techniques in your daily interactions with AI. More importantly, cultivate a habit of evaluation and reflection: for the same task, try different prompting approaches (e.g., rephrase instructions, add/remove context, change format requirements, include examples or CoT guidance). Then, carefully observe and compare the differences in output quality, relevance, accuracy, logic, completeness, etc. Actively think about why one prompt worked better or worse than another. Was the instruction imprecise? Did the context introduce noise? Is the model more “sensitive” to certain phrasing? Learning from mistakes and suboptimal results, and continually adjusting and optimizing your prompts, is the core path to skill improvement.
  • Systematically Organize and Share Your “Prompt Assets”: For prompts repeatedly proven effective and reliable in your practice—especially those for common, patterned legal tasks you frequently handle (e.g., risk review templates for specific contract types, case summary generation templates, memo framework prompts, client email draft prompts)—be sure to systematically organize, label (note use case, key variables, caveats), and save them. Build a personal or team “Prompt Asset Library” or “Best Practices Collection.” This is an invaluable resource for boosting future efficiency on similar tasks (reuse or adapt) and a great way for team knowledge sharing, experience transfer, and capability building.
  • Deeply Understand the Characteristics of the Models You Use: Different LLMs (from OpenAI, Anthropic, Google, Meta, or domestic providers in China like Baidu, Alibaba, Zhipu, Moonshot) likely differ significantly in their underlying training data composition, architectural details, and alignment training methods. This leads to variations in their strengths (e.g., creativity vs. reasoning, Chinese understanding), “sensitivity” to prompt phrasing, ability to follow complex instructions, tendency towards “hallucination,” and grasp of specific domain knowledge. Therefore, beyond mastering general techniques, you also need to gradually learn and adapt to the specific “personality” and “preferences” of the model(s) you primarily use, understanding their “pros” and “cons” to better “leverage strengths and mitigate weaknesses.”
  • Be Patient, Embrace the Iterative Process: Almost no one writes the perfect prompt on the first try, especially for complex tasks. Prompt engineering is inherently an iterative cycle of “design-test-evaluate-optimize.” Don’t be discouraged when your initial attempt doesn’t yield satisfactory results. Analyze the issues carefully, then try adjusting one aspect of the prompt (clearer instruction? more relevant context? specific format? add an example? guide thinking steps?), run it again, observe improvements. Sometimes it might take multiple, even dozens, of revisions and experiments to gradually approach the desired high-quality output. Be patient, view every imperfect output as a learning opportunity, and enjoy the process of continuous optimization and growing mastery.

Through systematic learning of theory, active engagement in practice, continuous reflection and summarization, combined with a deep understanding of the specific models used, you will gradually master the art and science of “dancing with AI” that is prompt engineering. Skillfully wielding these basic and advanced prompting techniques will empower you, the “AI conductor,” to more precisely, efficiently, and safely guide the powerful “intelligent orchestra” of Large Language Models, composing beautiful symphonies of enhanced quality, efficiency, and creativity in your complex legal work. The next chapter will focus on tailoring practical, effective prompt templates for common, specific legal tasks, truly grounding these techniques in your daily practice.