Counterfactual Reasoning logo

Counterfactual Reasoning

Community
vivy-yi
counterfactual-reasoning

反事实推理——评估"如果某一事实不存在/发生改变,法律结果将如何不同"。 适用情形:因果关系认定(若无该行为,损害是否仍会发生)、过错与责任比例划分、损害赔偿范围确定、合同违约损失计算。 核心方法:构建一个与现实世界仅在目标变量上不同的"反事实世界",比较两个世界的结果差异。 经典方法:But-for检验(若无A则无B)、NESS检验(不可或缺条件)。

Overview

Publishervivy-yi
RepositoryGreater-China-Legal
Skill namecounterfactual-reasoning
Stars
49
Forks
9
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by vivy-yi on GitHub. Read the source before you install it.

Installation

Install the Counterfactual Reasoning AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/vivy-yi/Greater-China-Legal/tree/main/plugins/legal-atomic/counterfactual-reasoning
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/vivy-yi/Greater-China-Legal.git /tmp/Greater-China-Legal
mkdir -p .claude/skills
cp -r /tmp/Greater-China-Legal/plugins/legal-atomic/counterfactual-reasoning .claude/skills/counterfactual-reasoning
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Counterfactual Reasoning in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Counterfactual Reasoning on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Counterfactual Reasoning is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

/counterfactual-reasoning — 反事实推理

核心概念

现实世界:A发生 → B发生
反事实世界:假设A未发生 → B是否仍然发生?

若B不再发生 → A是B的原因(具有因果贡献)
若B仍然发生 → A不是B的原因(无因果贡献)

关键术语

术语含义
目标变量被假设改变/移除的事实/行为/条件
结果变量需要观察是否变化的法律后果
反事实世界目标变量被改变后的假设情境
But-for检验"若非"检验——若非A,则B不会发生
NESS检验不可或缺条件检验

工作流程

步骤1:确定分析框架

1. 明确目标变量:哪个事实/行为/条件要被假设改变
2. 明确结果变量:哪个法律结果要被评估
3. 确定背景条件:反事实世界中保持不变的其他事实

步骤2:构建反事实世界

构建一个与现实世界完全相同的世界,
除了目标变量被改变/移除。

关键问题:
- 其他所有背景条件是否保持不变?
- 改变目标变量后,现实世界的时间线如何调整?

步骤3:执行But-for检验

现实世界:A发生 → B发生
反事实世界:假设A未发生
  → 若B不发生:But-for因果关系成立
  → 若B仍然发生:无But-for因果关系

注意:必须考虑反事实世界中其他条件是否需要调整
(替代原因/阻断原因的问题)

步骤4:NESS检验(补充)

NESS = 必要充分条件集合

对结果B的每个必要条件X:
- 如果X的缺失会导致B不发生 → X是B的必要条件
- 如果X的集合中每个成员的缺失都会导致B不发生 → 该集合是B的NESS

NESS检验比简单But-for更严格,
可排除替代原因造成的虚假因果。

步骤5:因果贡献评估

如果But-for成立:
  → 评估目标变量对结果的贡献程度
  → 在多因一果的情况下,评估各原因的相对贡献
  → 考虑因果中断的可能性(介入原因)

如果But-for不成立:
  → 目标变量不是法律上的原因
  → 可能需要考虑其他因果理论(预见性因果、重要性因果)

常见应用场景

侵权法:因果关系认定

问题:若无被告的过失行为,原告的损害是否仍会发生?

现实:被告超速 → 碰撞 → 原告受伤
反事实:被告未超速 → 碰撞是否仍会发生?
  → 如果正常速度足以避免碰撞 → 因果关系成立
  → 如果碰撞仍会发生(不可避免)→ 因果关系不成立

合同法:违约损失计算

问题:如果合同未被违约,债权人本可获得的利益是多少?

现实:违约方违约 → 债权人损失X
反事实:违约方履行 → 债权人本可获得Y
损失 = Y - X(可得利益损失)

损害赔偿:可预见性限制

问题:如果违约方违约但非违约方未遭受损害,是否需要赔偿?

反事实检验:若无违约方的违约行为,损害是否仍会发生?
  → 如果损害无论如何都会发生 → 违约方的因果贡献有限
  → 如果损害因违约才发生 → 因果关系成立

输出格式

## 反事实推理报告

### 分析框架
- 目标变量:[被假设改变的事实]
- 结果变量:[要评估的法律后果]
- 背景条件:[保持不变的其他事实]

### 现实世界
[现实世界的事实链]

### 反事实世界
[反事实世界(目标变量改变后)的事实链]

### 因果检验
- But-for检验:[通过/未通过]
- NESS检验:[通过/未通过]
- 结果:[因果关系成立/不成立]

### 因果贡献评估
[在多因一果情况下的相对贡献]

### 法律结论
[基于因果关系认定的法律后果]

### 置信度:🟢高 / 🟡中 / 🔴低
- 不确定性来源:[...]

引用说明

本skill方法论来自 THUYRan/Legal-Skills-Chinese/counterfactual-reasoning, THUYRan原版19000字,GCL精简至约180行,保留核心流程和But-for检验框架。

Frequently asked questions

What does the Counterfactual Reasoning AI skill do?

反事实推理——评估"如果某一事实不存在/发生改变,法律结果将如何不同"。 适用情形:因果关系认定(若无该行为,损害是否仍会发生)、过错与责任比例划分、损害赔偿范围确定、合同违约损失计算。 核心方法:构建一个与现实世界仅在目标变量上不同的"反事实世界",比较两个世界的结果差异。 经典方法:But-for检验(若无A则无B)、NESS检验(不可或缺条件)。

Why use Counterfactual Reasoning on TypingMind?

Because you install it once and use it with any model. Counterfactual Reasoning is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Counterfactual Reasoning in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/vivy-yi/Greater-China-Legal/tree/main/plugins/legal-atomic/counterfactual-reasoning. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Counterfactual Reasoning?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Counterfactual Reasoning?

As many as you like. As long as a model supports skills, you can use Counterfactual Reasoning with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Counterfactual Reasoning AI skill free?

It is published on GitHub by vivy-yi. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇