法律分野のプロンプトパターン
契約分析、条項抽出、管轄区域を考慮した法律向けプロンプトを学びます。
「法律分野のプロンプトパターン」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。
法務分野のプロンプト設計が異なる理由
法務分野のプロンプト設計には、管轄への配慮、正確な言語、リスク意識、必須免責事項が必要です。注意書きなしに助言を行う法務AIツールは、ユーザーを法的責任のリスクにさらします。分野固有のパターンによって、これらの制約に体系的に対応できます。
弁護士ペルソナのシステムプロンプト
専門家ペルソナを設定し、管轄の範囲を明示すると、モデルの分析を正しく方向付けられます。必ず守秘義務と免責事項に関する通知を含めます。
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].textPydanticによる構造化された法務出力
法務分析をプログラムで処理する必要があるパイプラインでは、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.')必須免責事項の注入
すべての法務AIの出力には免責事項を付ける必要があります。毎回含めるようモデルに任せるのではなく、アプリケーション層でプログラムによって注入します。これにより、誤って省略されることがなくなります。
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確認テスト
法務AIツールを構築する場合、免責事項はどこに注入すべきですか?
法務分野のプロンプト設計のまとめ
法務分野のプロンプト設計には、次のような必須パターンがあります。
- 管轄の範囲:システムプロンプトで準拠法を明示します
- 構造化出力:機械で処理できる分析には、JSONまたは番号付きリストを使用します
- レッドフラグライブラリ:問題のある既知の条項のプレイブックを維持します
- 引用の規律:引用を必須とし、確信のない引用には[VERIFY]を付けます
- 必須免責事項:モデルに任せず、アプリケーション層で注入します
- 秘匿特権の対象データの取り扱い:システムプロンプトに機密保持の指示を含めます
よくある質問
「法律分野のプロンプトパターン」レッスンは無料ですか?
はい。「法律分野のプロンプトパターン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。
「法律分野のプロンプトパターン」で何を学びますか?
契約分析、条項抽出、管轄区域を考慮した法律向けプロンプトを学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
AI Prompt Engineeringを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「法律分野のプロンプトパターン」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAI Prompt Engineeringレッスンでコードを書いて実行できますか?
はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 法律分野のプロンプトパターン
- 医療・臨床プロンプト
- 金融・定量分析プロンプト
- ドメイン用語集とオントロジーの注入