0Pricing
AI Prompt Engineering · 课时

法律领域的提示词模式

合同分析、条款提取和考虑司法管辖区的法律提示词。

法律领域的提示词模式 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。

法律领域提示词为何不同

法律领域的提示词编写需要了解司法辖区、使用精确措辞、具备风险意识,以及提供强制性免责声明。法律人工智能工具如果在没有附带限制说明的情况下提供建议,就会使用户面临责任风险。专门针对该领域的模式可以系统地应对这些限制。

律师角色系统提示词

通过明确司法辖区范围来设定专家角色,可以正确限定模型的分析方向。请始终加入保密声明和免责声明。

LEGAL_SYSTEM_PROMPT = '''You are an experienced commercial lawyer reviewing contracts
under New York law (NYCL, UCC Article 2, and applicable federal law).

When analyzing contracts:
1. Identify the governing law clause and note if it conflicts with NY law.
2. Flag any provisions that deviate from NY commercial norms.
3. Use precise legal terminology — do not paraphrase statutes.
4. Always cite the relevant section or clause number from the contract.
5. Structure your analysis as: [Issue] -> [Risk Level: LOW/MEDIUM/HIGH] -> [Recommendation].

DISCLAIMER: This analysis is for informational purposes only and does not
constitute legal advice. Always consult a licensed attorney before acting
on any legal analysis. Attorney-client privilege does not apply to this
communication.'''

import anthropic
client = anthropic.Anthropic(api_key='YOUR_API_KEY')

合同条款提取模式

提取提示词必须经过结构化设计,以返回机器可解析的输出。请明确指定所需字段和输出格式,以确保不同文档之间保持一致。

EXTRACTION_PROMPT = '''Extract the following clauses from the contract below.
For each clause, provide:
- clause_type: one of [governing_law, limitation_of_liability, indemnification,
  termination, intellectual_property, confidentiality, arbitration, force_majeure]
- section_number: as it appears in the contract
- verbatim_text: exact text of the clause (do not paraphrase)
- jurisdiction_specific_notes: any NY-law-specific observations

If a clause is absent, set verbatim_text to null and note "Not found".
Return a JSON array.

Contract:
{contract_text}'''

import json

def extract_clauses(contract_text):
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=4096,
        system=LEGAL_SYSTEM_PROMPT,
        messages=[{'role': 'user', 'content':
            EXTRACTION_PROMPT.format(contract_text=contract_text)}]
    )
    return json.loads(response.content[0].text)

风险识别模式

风险识别提示词会指导模型按照严重程度对风险进行分类,并提供建议的缓解措施,使输出能够直接用于法律审查。

RISK_PROMPT = '''Perform a legal risk analysis of the following contract
under New York law. Identify up to 10 risks.

For each risk output:
1. Risk title (concise, max 8 words)
2. Severity: CRITICAL | HIGH | MEDIUM | LOW
3. Clause reference (section number)
4. Risk description (2-3 sentences)
5. Recommended mitigation (1-2 sentences)

Prioritize: limitation of liability caps, indemnification exposure,
unlimited IP assignment, auto-renewal traps, one-sided termination rights.

Contract:
{contract_text}

Format as a numbered list with clear labels.'''

def identify_risks(contract_text):
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=3000,
        system=LEGAL_SYSTEM_PROMPT,
        messages=[{'role': 'user', 'content':
            RISK_PROMPT.format(contract_text=contract_text)}]
    )
    return response.content[0].text

了解司法辖区的对比

审查受另一司法辖区管辖的合同时,应指导模型突出差异,即指出哪些内容不同于预期司法辖区的通常规范。

JURISDICTION_COMPARE_PROMPT = '''The contract below is governed by {governing_law} law.
I am a New York-based company. Analyze:

1. Key differences between {governing_law} and New York law that affect this contract.
2. Provisions that are enforceable under {governing_law} but may not be under NY law.
3. Choice-of-law risks if we add a NY-law addendum.
4. Recommended: should we negotiate to change governing law to NY? Why or why not?

Contract:
{contract_text}'''

def compare_jurisdictions(contract_text, governing_law):
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=2000,
        system=LEGAL_SYSTEM_PROMPT,
        messages=[{'role': 'user', 'content':
            JURISDICTION_COMPARE_PROMPT.format(
                governing_law=governing_law,
                contract_text=contract_text
            )}]
    )
    return response.content[0].text

系统提示词中的保密条款

为律师事务所构建法律工具时,系统提示词必须包含保密条款和数据处理说明,以保护客户的法律特权并符合专业责任规则。

PRIVILEGED_SYSTEM_PROMPT = '''You are a legal research assistant for
{firm_name}, a licensed law firm.

CONFIDENTIALITY NOTICE:
- All documents shared in this session are attorney-client privileged.
- Do not include client names, matter numbers, or identifying details
  in any output that may be logged externally.
- Do not store, reference, or infer information from previous sessions.
- Treat all information as confidential per Model Rules of Professional
  Conduct 1.6 (Confidentiality of Information).

SCOPE:
- Your role is legal research and document analysis only.
- You do not represent the client and do not provide legal advice directly.
- Flag all outputs with: "Review required by licensed attorney before use."

REFUSAL RULE:
- If asked to draft strategy for concealing evidence or misleading a court,
  refuse and explain that this violates professional responsibility rules.'''

print(PRIVILEGED_SYSTEM_PROMPT.format(firm_name='Smith & Associates LLP')[:200])

NDA 摘要模式

保密协议(NDA)具有标准结构。针对性的提取提示词可以提取 NDA 审查中重要的关键商业条款。

NDA_SUMMARY_PROMPT = '''Summarize this NDA for a business executive.
Extract these exact fields (be concise, max 2 sentences per field):

1. Parties: Who are the disclosing and receiving parties?
2. Purpose: Why is information being shared?
3. Confidential Information Definition: What is and is not covered?
4. Term: How long does confidentiality last?
5. Exclusions: What information is not protected?
6. Return/Destroy: What happens to confidential info after the relationship ends?
7. Remedies: What happens if the NDA is breached?
8. Key Risks: List up to 3 issues that deviate from standard market practice.

NDA Text:
{nda_text}

End with a one-sentence verdict: "This NDA is [FAVORABLE / BALANCED / UNFAVORABLE]
for the receiving party because _____."'''

def summarize_nda(nda_text):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1500,
        system=LEGAL_SYSTEM_PROMPT,
        messages=[{'role': 'user', 'content':
            NDA_SUMMARY_PROMPT.format(nda_text=nda_text)}]
    )
    return response.content[0].text

使用 Pydantic 的结构化法律输出

对于需要以编程方式处理法律分析的流程,请通过 Pydantic 模型使用结构化输出,以确保每个字段都存在且类型正确。

from pydantic import BaseModel
from typing import List, Optional
from enum import Enum

class RiskLevel(str, Enum):
    CRITICAL = 'CRITICAL'
    HIGH = 'HIGH'
    MEDIUM = 'MEDIUM'
    LOW = 'LOW'

class LegalRisk(BaseModel):
    title: str
    severity: RiskLevel
    clause_reference: str
    description: str
    mitigation: str

class ContractAnalysis(BaseModel):
    governing_law: str
    contract_type: str
    effective_date: Optional[str]
    term_years: Optional[float]
    risks: List[LegalRisk]
    overall_recommendation: str
    disclaimer: str = (
        'This analysis is informational only and does not constitute '
        'legal advice. Consult a licensed attorney before acting.'
    )

# Use with structured output (pseudo-code)
# analysis = ContractAnalysis.model_validate_json(llm_response)
# for risk in analysis.risks:
#     print(f'[{risk.severity}] {risk.title}: {risk.description}')

风险警示条款检测

请建立一个已知风险警示合同条款库,并指导模型检测这些条款。这样可以创建可复用的工作方案,并随着法律团队的意见不断改进。

RED_FLAGS = [
    'unlimited indemnification with no cap',
    'unilateral right to modify terms without notice',
    'IP assignment of all work product ("work for hire" with no carve-outs)',
    'non-compete broader than 1 year or 100 miles',
    'automatic renewal with short cancellation window (< 30 days)',
    'no limitation of liability clause (unlimited damages)',
    'mandatory arbitration in unfavorable jurisdiction',
    'liquidated damages clause that may be penalty clause under NY law',
]

RED_FLAG_PROMPT = '''Review the contract below for the following red-flag provisions.
For each red flag found, quote the relevant text and rate severity 1-5.
If not found, mark as "Not Present".

Red Flags to Check:
{red_flag_list}

Contract:
{contract_text}'''

def detect_red_flags(contract_text):
    flags_text = '\n'.join(f'{i+1}. {f}' for i, f in enumerate(RED_FLAGS))
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        system=LEGAL_SYSTEM_PROMPT,
        messages=[{'role': 'user', 'content':
            RED_FLAG_PROMPT.format(
                red_flag_list=flags_text,
                contract_text=contract_text
            )}]
    )
    return response.content[0].text

引用与法条参照

引用可以提升法律分析的权威性。请提示模型引用相关法条、法规和判例法,并始终要求它在无法确定引用是否准确时予以标明。

CITATION_PROMPT = '''Analyze the indemnification clause below under New York law.

For your analysis:
1. Cite the relevant NY statutes (e.g., NY General Obligations Law sections).
2. Reference applicable UCC provisions if relevant.
3. Cite at least one landmark NY case on indemnification interpretation.
4. If you are not certain a citation is accurate, prefix it with
   "[VERIFY: " and end with "]" — never fabricate case citations.
5. Distinguish between indemnification for third-party claims vs.
   direct damages between the parties.

Indemnification Clause:
{clause_text}'''

# Best practice: always post-process LLM citations with a legal database check
# (Westlaw, LexisNexis API) before relying on them in actual legal work
print('REMINDER: Always verify LLM-generated citations with a legal database.')

注入强制免责声明

每个法律人工智能输出都必须附带免责声明。请在应用层以编程方式注入免责声明,不要依赖模型每次都自行添加。这样可以确保免责声明不会被意外遗漏。

LEGAL_DISCLAIMER = (
    '\n\n---\n'
    'DISCLAIMER: This analysis is generated by an AI system and is '
    'provided for informational purposes only. It does not constitute '
    'legal advice and does not create an attorney-client relationship. '
    'Laws vary by jurisdiction and change over time. Always consult a '
    'licensed attorney in your jurisdiction before making legal decisions.'
)

def get_legal_analysis(prompt, system_prompt=LEGAL_SYSTEM_PROMPT):
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=2000,
        system=system_prompt,
        messages=[{'role': 'user', 'content': prompt}]
    )
    raw_output = response.content[0].text
    # Always inject disclaimer at application layer
    return raw_output + LEGAL_DISCLAIMER

analysis = get_legal_analysis('Summarize the key risks in this contract: ...')
print(analysis[-200:])  # Shows disclaimer at end

快速检查

构建法律人工智能工具时,应在哪里注入免责声明?

法律领域提示词总结

法律领域的提示词编写需要遵循以下几项不可妥协的模式:

  • 司法辖区范围:在系统提示词中明确指定适用法律
  • 结构化输出:使用 JSON 或编号列表,以便机器处理分析结果
  • 风险警示库:维护已知问题条款的工作方案
  • 引用规范:要求提供引用,并使用 [VERIFY] 标记不确定的引用
  • 强制免责声明:在应用层注入,而不是交由模型处理
  • 特权数据处理:在系统提示词中加入保密说明

常见问题解答

「法律领域的提示词模式」课时是免费的吗?

是的 — 「法律领域的提示词模式」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。

「法律领域的提示词模式」这节课中我会学到什么?

合同分析、条款提取和考虑司法管辖区的法律提示词。 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 AI Prompt Engineering 需要有经验吗?

无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「法律领域的提示词模式」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 AI Prompt Engineering 课中编写并运行代码吗?

能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 法律领域的提示词模式
  2. 医学与临床提示词
  3. 金融与定量分析提示词
  4. 领域术语表与本体注入
← 返回 AI Prompt Engineering