关于 legal-writer
用于起草 DOCX 法律文件的技能,涵盖合同、诉状、备忘录和法律意见等。其工作流逐节写作并验证文档,还提供判例与法规检索脚本。
主要功能
- 01起草 DOCX 法律文件
- 02逐节验证文档
- 03按文档类型提供模板与指引
- 04通过 CourtListener 检索判例
- 05检索 eCFR 与 Federal Register
适用场景
- 01准备合同或协议
- 02起草诉讼备忘录或法律意见书
- 03撰写诉状或索赔函
- 04核对引文和法规来源
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ kortix-ai/ kortix-registry --skill legal-writer安装后在 Claude Code 中输入/legal-writer确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/bluebook.mddocument-types.mdscripts/courtlistener.pyecfr_lookup.pyverify-legal.py详细介绍
法律文书撰写
以测试驱动工作流起草可供发布的高质量 DOCX(Word)法律文书:每完成一个部分,都要先进行验证,再继续下一部分。适用于合同、备忘录、诉状、投诉书、催款函等文书。
捆绑资源
通过 glob("**/KORTIX-legal-writer/") 查找技能目录。
| 资源 | 路径 | 用途 |
|---|---|---|
| 验证器 | scripts/verify-legal.py | TDD 验证套件(10 项检查) |
| 判例法 API | scripts/courtlistener.py | 使用 CourtListener 搜索和查询判例引文 |
| 法规 API | scripts/ecfr_lookup.py | 查询 eCFR 和 Federal Register 中的法规 |
| Bluebook 参考 | references/bluebook.md | Bluebook 引文格式速查 |
| 文书类型参考 | references/document-types.md | 各类文书的章节模板 |
TDD 规则
每完成文书中的一个部分后:
1. WRITE section content
2. GENERATE: build/update the DOCX via the docx skill
3. VERIFY: python3 verify-legal.py legal/{slug}/
4. If FAIL → FIX → go to 2
5. If PASS → move to next section
文书必须在每一步都通过验证。切勿一次性批量修复错误。
流程概览
Phase 1: SCAFFOLD → Create project, metadata.json, empty DOCX with structure
Verify: document exists and has correct sections ✓
Phase 2: RESEARCH → Case law, statutes, regulations (if litigation/regulatory doc)
Verify: citations are formatted correctly ✓
Phase 3: WRITE → Per-section drafting in logical order
Verify: verify-legal.py after EACH section ✓
Phase 4: POLISH → Self-reflection pass, strict verification, final DOCX
Verify: verify-legal.py --strict with zero warnings ✓
文件系统架构
legal/{document-slug}/
├── metadata.json # Document type, parties, jurisdiction, etc.
├── document.docx # The main document (generated via docx)
├── research/ # Case law, statutes, notes (optional)
│ ├── cases.json # CourtListener search results
│ ├── regulations.json # eCFR lookup results
│ └── notes.md # Research notes
└── versions/ # Prior versions (optional)
metadata.json
此文件用于驱动验证。在搭建项目框架时创建:
{
"type": "contract",
"title": "Services Agreement",
"jurisdiction": "State of Delaware",
"governing_law": "Delaware",
"date": "2025-01-15",
"parties": [
{"name": "Acme Corporation", "short_name": "Company", "role": "client"},
{"name": "Jane Smith Consulting LLC", "short_name": "Contractor", "role": "contractor"}
],
"word_limit": null,
"page_limit": null
}
对于法律意见书和动议,请根据法院规则填写 word_limit 或 page_limit。
阶段 1:搭建框架
1a. 确定文书类型
阅读 references/document-types.md,查找与所需文书类型相匹配的章节模板。主要类型包括:
| 类型 | 键 | 用途 |
|---|---|---|
| 法律备忘录 | memo | 内部分析、预测性分析 |
| 动议法律意见书 | brief | 说服性文书、法院提交文件 |
| 合同/协议 | contract | 交易性安排、双方义务 |
| 投诉书/申请书 | complaint | 提起诉讼 |
| 催款函 | demand | 诉前索赔 |
| 法律意见书 | opinion | 交易所需的正式法律意见 |
| 证据开示请求 | discovery | 书面询问、文件请求 |
| 和解协议 | settlement | 解决争议 |
| 服务条款 | tos | 面向用户的条款 |
| 隐私政策 | privacy | 数据隐私合规 |
1b. 创建项目结构
SLUG="document-slug-here"
mkdir -p "legal/$SLUG"/{research,versions}
1c. 创建 metadata.json
编写 JSON 文件,填写文书类型、当事方、管辖权以及任何限制条件。
1d. 生成初始 DOCX
加载 docx 技能。使用 python-docx 创建文档,并设置:
- 使用恰当的标题样式(通过 Heading 1、2、3 构建章节结构)
- 12pt 字号(法院文件使用 Times New Roman 或类似的衬线字体)
- 1 英寸页边距(根据管辖权调整,参见法院规则)
- 法律意见书和法院文件使用双倍行距,合同使用单倍行距
- 正确的页码
- 章节标题与
references/document-types.md中的文书类型模板一致 - 在每个章节中添加占位文本:
[TO BE DRAFTED]
1e. 验证:首次通过
python3 verify-legal.py legal/$SLUG/
搭建框架后的文档应当已存在,且结构正确。此阶段允许使用占位符(它们会被标记为警告,而非失败,除非使用 --strict)。
阶段 2:法律研究(如适用)
对于诉讼文书(备忘录、法律意见书、投诉书)和监管文书,应在撰写前研究判例法和法规。
判例法检索(CourtListener)
SKILL_DIR="..." # from glob
# Search for relevant cases
python3 "$SKILL_DIR/scripts/courtlistener.py" search "search terms" --after 2015 --limit 10
# Get specific opinion details
python3 "$SKILL_DIR/scripts/courtlistener.py" opinion 12345
# Format as Bluebook citation
python3 "$SKILL_DIR/scripts/courtlistener.py" bluebook 12345
将结果保存到 research/cases.json。提取关键裁判要旨,以便在文书中使用。
**注意:**CourtListener 需要免费的 API 令牌才能提高请求速率限制。设置 COURTLISTENER_API_TOKEN 环境变量。不使用令牌时,每天最多只能发送 100 次请求。
法规检索(eCFR)
# Search regulations
python3 "$SKILL_DIR/scripts/ecfr_lookup.py" search "employment discrimination" --title 29
# Get specific CFR section
python3 "$SKILL_DIR/scripts/ecfr_lookup.py" section 16 444.1
# Search Federal Register for recent rules
python3 "$SKILL_DIR/scripts/ecfr_lookup.py" fedreg "data privacy"
无需 API 密钥。
引用格式
阅读 references/bluebook.md,了解 Bluebook 引用格式。主要规则:
- 判例: Party v. Party, Vol Reporter Page, Pin (Court Year)。
- 法规: Title U.S.C. § Section (Year)。
- 规章: Title C.F.R. § Section (Year)。
- 必须标明具体页码 — 始终引用具体页码。
- 首次完整引用后使用简写形式: Id.、supra,或当事方名称 + reporter。
对于非诉讼文件(合同、服务条款),通常不需要正式引用 — 只需按名称和条款引用适用法律。
阶段 3:分节写作
按文件类型确定写作顺序
合同: 定义 → 核心义务 → 陈述与保证 → 赔偿 → 责任限制 → 期限/终止 → 一般条款 → 序言/前言陈述(最后撰写,待范围明确后)
备忘录: 提出的问题 → 简要答复 → 事实陈述 → 讨论(每个问题按 IRAC 结构展开)→ 结论
诉讼文书: 事实陈述 → 论证(先写最有力的要点)→ 引言/摘要(最后撰写,待明确论点后)→ 结论
起诉状: 当事方 → 管辖权/审判地 → 事实陈述 → 诉因 → 救济请求
写作循环(逐节进行)
1. READ all previously written sections for context
2. WRITE the section following document-type conventions
3. REGENERATE the DOCX (update via python-docx)
4. VERIFY: python3 verify-legal.py legal/{slug}/
5. If errors → FIX → go to 3
6. SELF-REFLECT:
- Is every legal assertion supported by authority? (litigation docs)
- Are defined terms used consistently?
- Any ambiguous language? ("reasonable" without standard, "timely" without deadline)
- Cross-references point to correct sections?
- No placeholder text remaining in this section?
7. REVISE if needed → regenerate → verify
8. Section DONE → next
法律写作标准
在所有章节中贯彻以下要求:
清晰优先于正式:
- 用“之前”,不用“在……之前”
- 用“关于”,不用“就……而言”
- 用“如果”,不用“倘若”
- 用“依据”,不用“根据……规定”
- 用“为了”,不用“以便”
准确性:
- “shall” = 职责/义务(当事方 SHALL 执行 X)
- “will” = 未来事件或声明
- “may” = 许可(当事方 MAY 执行 X)
- “must” = 条件/要求
- “shall”只能用于规定义务
定义术语:
- 首次使用时定义:
"Effective Date" means [definition]. - 全文统一大写:始终使用“Effective Date”,不要使用“effective date”
- 在定义章节中按字母顺序排列
- 不要过度定义(常见英语词汇无需定义)
句子结构:
- 使用主动语态:“承包方应交付”,而非“应完成交付”
- 将重点前置:先写执行主体和动作
- 合同中每句话表达一个意思(每项义务 = 一句话)
- 段落简短(说服性写作中最多 4-5 句话)
数字和日期:
- 数字 1-9 用英文拼写,10 及以上用数字
- 日期:“January 15, 2025”(全文格式一致)
- 金额:“$50,000”或“Fifty Thousand Dollars ($50,000)”(合同中两种形式均可)
- 时间期限:合同中用“thirty (30) days”;备忘录/诉讼文书中用“30 days”
各章节的具体指导
合同:定义章节
"Agreement" means this Services Agreement, including all exhibits and schedules.
"Confidential Information" means any information disclosed by one party to the
other that is designated as confidential or that reasonably should be understood
to be confidential given the nature of the information and the circumstances of
disclosure.
"Deliverables" means the work product to be delivered by Contractor as described
in Exhibit A.
合同:责任限制
IN NO EVENT SHALL EITHER PARTY BE LIABLE TO THE OTHER PARTY FOR ANY
INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES,
REGARDLESS OF THE CAUSE OF ACTION OR THE THEORY OF LIABILITY, EVEN IF
SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
THE TOTAL AGGREGATE LIABILITY OF [PARTY] UNDER THIS AGREEMENT SHALL NOT
EXCEED THE TOTAL FEES PAID BY [OTHER PARTY] DURING THE TWELVE (12) MONTH
PERIOD PRECEDING THE CLAIM.
备忘录:IRAC 讨论结构
针对每个法律问题:
[ISSUE] The issue is whether [legal question under specific law/standard].
[RULE] Under [jurisdiction] law, [state the rule]. See [Authority]. The [court]
has held that [rule elaboration]. [Authority]. Courts consider [factors/elements]:
(1) [factor]; (2) [factor]; and (3) [factor]. [Authority].
[APPLICATION] Here, [apply each factor to the client's facts]. First, [fact]
satisfies [factor] because [reasoning]. See [analogous case]. Unlike in
[distinguishable case], where [different facts led to different outcome], here
[explain why our facts are more like the favorable case].
[CONCLUSION] Therefore, [conclusion on this issue]. A court would likely
[prediction].
诉讼文书:论证标题
标题应为完整且具有说服力的句子:
Good: "I. THE TRIAL COURT ERRED BY GRANTING SUMMARY JUDGMENT BECAUSE
GENUINE DISPUTES OF MATERIAL FACT EXIST."
Bad: "I. SUMMARY JUDGMENT"
Good: "A. Plaintiff's Deposition Testimony Creates a Triable Issue of Fact
Regarding Defendant's Knowledge of the Defect."
Bad: "A. Deposition Testimony"
起诉状:编号段落
每项事实主张都应单独列为一个编号段落:
12. On or about March 15, 2024, Plaintiff entered into a written agreement
with Defendant for the purchase of the Property (the "Purchase Agreement").
A true and correct copy of the Purchase Agreement is attached hereto as
Exhibit A and incorporated by reference.
13. Pursuant to Section 4.1 of the Purchase Agreement, Defendant represented
and warranted that the Property was free of all environmental contamination.
14. On or about June 1, 2024, Plaintiff discovered that the Property contained
significant levels of lead contamination in the soil.
阶段 4:润色与最终核验
4a. 自我检查
重新通读整份文件并检查:
- 一致性: 全文术语、当事方名称和定义术语保持一致
- 完整性: 包含该文件类型所需的全部章节,逻辑无缺漏
- 交叉引用: 重新排列章节后,每处“Section X.Y”引用均准确无误
- 定义术语: 每个首字母大写的术语都有定义,且每个定义都得到使用
- 歧义: 不存在缺少标准的模糊术语,也没有指代不明的代词
- 占位符: 不留任何
[INSERT]、[TBD]、[TODO]或空白行 - 日期和数字: 全文格式一致
- 引用:(适用于诉讼文件)所有引用均符合 Bluebook 格式并标明具体页码
4b. 严格核验
python3 "$SKILL_DIR/scripts/verify-legal.py" "legal/$SLUG/" --strict
所有检查项都必须通过:
- 文档存在,且大小并非微不足道
- 定义术语:全部已定义、全部已使用,且大小写一致
- 交叉引用:章节/附件/附表引用有效
- 引证:格式正确(仅限诉讼文书)
- 不含占位符/待办事项/草稿痕迹
- 当事人名称使用一致
- 包含必需的标准条款(合同)
- 情态动词使用一致(shall/must/may/will)
- 字数在限制范围内(诉讼文书)
- 日期格式一致
4c. 最终输出
交付文件为 legal/{slug}/document.docx。如果用户需要 PDF,请进行转换:
# If libreoffice is available:
libreoffice --headless --convert-to pdf "legal/$SLUG/document.docx" --outdir "legal/$SLUG/"
# Or use python-docx2pdf:
pip install docx2pdf && python3 -c "from docx2pdf import convert; convert('legal/$SLUG/document.docx')"
DOCX 格式标准
生成 DOCX 时(通过 docx skill / python-docx):
法院文书(诉状、动议、起诉书)
- 字体: Times New Roman,12pt(或 Century Schoolbook 12pt)
- 间距: 正文使用双倍行距
- 页边距: 四边均为 1 inch(检查当地规则——部分地区要求左侧为 1.5")
- 页码: 底部居中
- 标题栏: 法院名称、当事人、案号——使用法院要求的格式
- 行号: 部分司法管辖区要求(例如,加利福尼亚州法院)
合同和交易文件
- 字体: Times New Roman 或 Calibri,11-12pt
- 间距: 单倍行距或 1.15 倍行距
- 页边距: 四边均为 1 inch
- 章节编号: Article → Section:1.1、1.2、2.1 等
- 定义术语: 首次定义时加粗
- 签名栏: 右对齐或居中,并留出签名/姓名/职务/日期填写行
- 全大写: 谨慎使用——仅用于责任限制和免责声明章节
- 页眉: 文档标题 + 适用时添加保密标记
- 页脚: 页码;工作草稿还需注明草稿日期
通用
- 标题样式: 使用 Word 的 Heading 1/2/3 样式(支持自动生成目录)
- 段落样式: 使用统一命名的样式,而非手动设置格式
- 分页符: 置于主要章节标题之前(合同中的 Article,诉讼文书中的主要章节)
- 孤行/寡行控制: 启用(避免页面顶部/底部出现孤行)
司法管辖区专属说明
提交任何法院文件前,务必检查当地规则。主要差异如下:
| 司法管辖区 | 字体 | 间距 | 页边距 | 特殊要求 |
|---|---|---|---|---|
| 联邦上诉法院 | 14pt 比例衬线字体 | 双倍 | 四边均为 1" | 字数限制因巡回区而异 |
| 美国最高法院 | 12pt Century | 2pt 行距 | 特殊文本区域 | 小册子格式 |
| 加利福尼亚州法院 | 13pt 及以上比例衬线字体 | 双倍 | 左右各 1.5" | 必须有行号 |
| 纽约州法院 | 12pt 及以上比例字体 | 双倍 | 四边均为 1" | 因法院而异 |
| 大多数联邦地区法院 | 12pt TNR 或类似字体 | 双倍 | 四边均为 1" | 检查当地规则 |
如有疑问,12pt Times New Roman、双倍行距、1-inch 页边距适用于大多数法院。