SuperAPI AI Directory

legal-risk-visualization

Data & analytics

View repository

Updated 10-16 05:00

About this skill

Legal Risk Visualization

Overview

  • Input: Legal analysis text (brief or detailed, either is acceptable)
  • Output: Structured risk analysis report (Markdown format + 4 PNG images)
  • Report language: Always Chinese
  • Core concept: The third layer (impact path diagram) is the sole data source, and the other three layers are derived from it
  • Rendering tools: matplotlib (radar chart, risk matrix) + mmdc (Mermaid impact path diagram, decision tree)
  • Target readers: Legal professionals + business decision-makers; the main body of the report does not use engineering abbreviations

This skill transforms linear legal analysis text into a networked risk structure, supporting internal decision-making and systematic risk management.

Nota simple risk scoring tool,buta visualization expression system for legal reasoning structures.

Terminology Standards

The following Chinese terms are used throughout the skill,and English abbreviations are not used in the main report:

Term Meaning Abbreviations allowed only in the appendix
Risk Index Comprehensive risk score of a single node NRS
Transmitted Risk Value Risk accumulated along a path PCR
Likelihood of Occurrence The probability that the risk occurs P
Severity of Impact The degree of damage caused by the risk I
Degree of Intervenability The degree to which the party can actively intervene C
Degree of Remediability The degree to which the consequences of the risk can be repaired R

Node types are distinguished in charts using color + legend,and type labels are not shown in the node text:

Internal Classification Chart Display Label Color
Fact Node Risk Source 🔴 Red #E74C3C
Legal Judgment Node Intermediate Link 🔵 Blue #3498DB
Risk Outcome Node Risk Consequence 🟠 Orange #F39C12
Business Impact Node Business Impact 🟣 Purple #9B59B6

Edge label simplification rules (numeric weights are retained only in the appendix):

Transmission Strength Chart Representation Fully annotated in the appendix
Strong transmission Thick arrow ==> Strong causality 0.9
Medium transmission Ordinary arrow --> Medium causality 0.6
Weak transmission/to be confirmed Dashed line -.-> + "待确认" Weak causality 0.3

Unified color scheme (consistent across all charts):

Color Color code Meaning
🟢 Green #27AE60 Safe/Low (Levels 1-2)
🟡 Yellow #F39C12 Attention/Medium (Level 3)
🔴 Red #E74C3C Alert/High (Levels 4-5)
🔵 Blue #3498DB Intervenable node
⚫ Gray #95A5A6 Relationship to be confirmed

Workflow (7 steps executed sequentially)

Step 1: Read and understand the legal analysis text

  1. Read through the full text and identify the legal domain (contract disputes, intellectual property, labor disputes, corporate governance, etc.)
  2. Determine the specific scenario and the parties involved
  3. Select the applicable risk dimensions (choose 4-6 from the following dimensions):
    • Compliance risk, litigation risk, financial risk, reputational risk, policy risk, enforcement risk, operational risk
    • Specific dimensions may be added based on industry characteristics
  4. Basis for dimension selection: the coverage of risk categories involved in the text

Step 2: Extract risk nodes

Identify the following types of statements from the text; each statement corresponds to one risk node:

Statement type Identification feature
Risk description "there is a risk of..." "may face..."
Uncertainty judgment "not yet clear" "to be confirmed" "there is a dispute"
Possible consequence "may lead to" "will face" "the consequence is"
Conditional trigger statement "if... then..." "once... then..." "under... circumstances"

Output a node list, with each node containing:

  • Number(N1, N2, ...)
  • Name(brief description)
  • Source text basis(original quotation)

Step 3: Classify nodes and establish causality

3a. Node classification

Classify each node as one of the following four types:

Type Definition Typical feature Chart label Color
Fact node An objectively existing state or condition Contract terms, events that have occurred Risk source 🔴 Red
Legal judgment node A judgment that requires legal reasoning to determine Liability determination, compliance judgment Intermediate link 🔵 Blue
Risk outcome node The final legal consequence Compensation, penalty, judgment result Risk consequence 🟠 Orange
Business impact node The actual impact on business operations Cash flow, reputation, operations Business impact 🟣 Purple

3b. Identify explicit causality

Identify direct causal relationships through logical connectives:

  • therefore, so, lead to, cause, trigger, make
  • if... then..., if... will..., once... then...
  • and then, thereby, subsequently, so that
  • due to, in view of, based on

Explicit causality → High confidence ●●●

3c. Identify implicit causality

Reference references/causal-patterns.md Identify three implicit patterns:

  1. Parallel implication type → Default low confidence ●○○
  2. Background presupposition type → Default medium confidence ●●○
  3. Professional common-sense type → Judge based on generality (general legal common sense → high, industry-specific → medium, speculative → low)

3d. Set edge weights

Transmission type Coefficient Applicable scenario
Strong transmission 0.9 The cause almost necessarily leads to the consequence
Medium transmission 0.6 The cause likely leads to the consequence
Weak transmission 0.3 The cause may lead to the consequence
Conditional transmission 0.1-0.9 Depends on specific conditions

Step 4: Calculate risk attributes

4a. Node attribute assessment

Assess four attributes for each node (0-1 range):

Attribute Meaning
Likelihood of occurrence The likelihood of this risk occurring
Severity of impact The degree of damage caused by this risk
Degree of intervenability The degree to which the party can intervene
Degree of remediability The degree to which the consequences of the risk can be repaired

4b. Calculate risk index

风险指数 = 发生可能性 × 影响严重性 × (1 - 可干预程度) × (1 - 可补救程度)

The complete calculation process for each node must be shown in the appendix.

4c. Calculate transmission risk value

传导风险值 = 起点风险指数 × ∏(边权重_i)

For processing rules, see references/formulas.md:

  • Branching: Each branch transmits independently
  • Convergence (OR, default): Take the maximum transmission risk value among incoming edges
  • Convergence (AND): Take the product of the transmission risk values of incoming edges (only when legal logic requires "simultaneous satisfaction")
  • Feedback loop: Identify via topological sorting, maximum 3 iterations, convergence condition < 5%

Step 5: Identify key nodes and paths

Identify the following four types of key nodes:

Node type Identification criteria Significance
Root node In-degree = 0 Risk source
Amplifier node High out-degree branching point Risk diffuser
Controllable node Degree of intervenability > 0.3 Priority intervention target
Key path node Located on the path with the maximum transmission risk value Core transmission chain

Critical path = the path with the maximum transmission risk value among all paths from root nodes to leaf nodes.

Step 6: Generate four-layer output

All data are derived from the third layer (impact path diagram).

First layer: Radar chart dimension scoring

  1. Group all leaf nodes by risk dimension
  2. Each dimension score = the maximum transmission risk value of leaf nodes under that dimension
  3. Map to 1-5 levels:
等级 = ceil(传导风险值 × 4) + 1,上限 5
  1. Use references/anchoring-tables.md the anchoring table in to calibrate level labels

Second layer: Risk matrix (matplotlib scatter plot)

Take all leaf nodes (terminal risks) and generate a matplotlib four-quadrant scatter plot:

  • Horizontal axis = likelihood of occurrence (0→1)
  • Vertical axis = impact severity (0→1)
  • Bubble size = risk index
  • Color = corresponding quadrant color (unified color scheme)
  • Four-quadrant Chinese labels: High Priority / Key Focus / Routine Monitoring / Continuous Observation

Data format (passed to render_risk_matrix.py):

[
  {"name": "节点名称", "p": 0.9, "i": 0.6, "score": 0.34},
  ...
]

Third layer: impact path diagram (Mermaid)

Generate a Mermaid flowchart following these rules:

graph TD
    %% 节点格式:去掉类型标签,仅保留简短描述
    %% N1["新规扩展假期天数"](不再写"事实节点")

    %% 边标签简化:
    %% 强传导:==>(粗箭头,无文字)
    %% 中传导:-->(普通箭头,无文字)
    %% 弱传导/待确认:-.->|"待确认"|

    %% 使用 subgraph 分组:
    subgraph 风险源头
        N1["新规扩展假期天数"]
    end
    subgraph 中间环节
        N2["..."]
    end
    subgraph 风险后果
        N5["..."]
    end
    subgraph 业务影响
        N6["..."]
    end

    %% 节点着色(按类型):
    %% 风险源头:fill:#E74C3C,stroke:#333,stroke-width:2px,color:white
    %% 中间环节:fill:#3498DB,stroke:#333,stroke-width:2px,color:white
    %% 风险后果:fill:#F39C12,stroke:#333,stroke-width:2px,color:white
    %% 业务影响:fill:#9B59B6,stroke:#333,stroke-width:2px,color:white
    %% 关键路径边:stroke:#E74C3C,stroke-width:3px
    %% 待确认边:stroke:#95A5A6,stroke-dasharray:5

Add a Chinese legend below the diagram:

Legend description: 🔴 Red = risk source | 🔵 Blue = intermediate link | 🟠 Orange = risk consequence | 🟣 Purple = business impact | Thick line = strong transmission relationship | Dashed line = relationship to be confirmed

Fourth layer: decision tree (Mermaid graph TD)

Generate a Mermaid decision tree based on actionable nodes (actionability > 0.3).

Diamond-shaped decision nodes useyes/no question format(not threshold values):

graph TD
    D1{"公司假期制度是否<br/>已按新规更新?"}
    D1 -->|"是"| A1["无需行动"]
    D1 -->|"否"| A2["建议尽快更新制度"]

    %% 行动节点交通灯色:
    %% 绿=无需行动:fill:#27AE60,color:white
    %% 黄=建议行动:fill:#F39C12,color:white
    %% 红=紧急行动:fill:#E74C3C,color:white
    %% 菱形节点:fill:#3498DB,color:white

Each decision node:

  • Convert the risk node name into ayes/no question("Is it…?" "Is there…?")
  • Branch labels use only "是" / "否"
  • Action nodes are colored according to urgency

Step 7: Output report and graphics rendering

Use the assets/report-template.md template to generate the complete Markdown report.

Report structure (layered design for two types of readers):

一、风险概览        ← 决策者看这里(1页,交通灯摘要表 + 雷达图 + 核心建议)
二、核心发现与建议   ← 决策者+法律人(叙事式风险发现,非节点表格)
三、风险全景图      ← 两类读者(4张图 + 每张图前一句中文引导语)
四、风险情景分析    ← 法律人用来讲故事的场景推演
五、行动方案        ← 两类读者(含负责部门、建议时限、预期效果)
附录:分析方法与计算详情 ← 仅法律专业人员参考(公式、完整计算过程)

Key output principles:

  • No English abbreviations appear in the main report(NRS/PCR/P/I/C/R only in the appendix)
  • No internal node type names appear in the main report(fact nodes/legal judgment nodes, etc.); distinguish them by color + legend
  • Narrative first: describe core findings in complete paragraphs, not piled-up tables
  • Scenario-based: for each key path, write a specific scenario walkthrough (facts→legal issues→possible consequences→response window)

7a. Graphics rendering steps

Dynamic canvas size calculation rules:

When rendering Mermaid diagrams, the canvas size needs to be dynamically adjusted according to the number of nodes to avoid overlapping text:

Number of nodes Recommended canvas size Applicable scenario
≤ 8 nodes 1200 x 900 Simple flow
9-12 nodes 1600 x 1200 Medium complexity
13-16 nodes 2000 x 1500 Relatively complex
> 16 nodes 2400 x 1800 High complexity

Note: Chinese text is wider than English, so it is recommended to add 20% width on top of the above.

Generate 4 PNG images in the output directory:

  1. First layer radar chart → risk_radar.png
    python3 ~/.claude/skills/legal-risk-visualization/scripts/render_radar.py \
      --data '{"维度1":分数, "维度2":分数, ...}' \
      --output <输出目录>/risk_radar.png
    
  2. Second layer risk matrix → risk_matrix.png(Use matplotlib, not Mermaid)
    python3 ~/.claude/skills/legal-risk-visualization/scripts/render_risk_matrix.py \
      --data '[{"name":"节点名称","p":0.9,"i":0.6,"score":0.34}, ...]' \
      --output <输出目录>/risk_matrix.png
    
  3. Third layer impact path diagram → impact_pathway.png
    • Write the graph TD Mermaid code to impact_pathway.mmd
    • Call the rendering script (dynamically set the size according to the number of nodes):
    # 影响路径图节点数量通常在 8-14 之间,建议使用 1600x1200
    python3 ~/.claude/skills/legal-risk-visualization/scripts/render_mermaid.py \
      --input <输出目录>/impact_pathway.mmd \
      --output <输出目录>/impact_pathway.png \
      --width 1600 --height 1200
    
  4. Fourth layer decision tree → decision_tree.png
    • Write the graph TD Mermaid code to decision_tree.mmd
    • Call the rendering script (dynamically set dimensions based on the number of nodes):
    # 决策树节点数量通常在 6-12 之间,建议使用 1400x1000
    python3 ~/.claude/skills/legal-risk-visualization/scripts/render_mermaid.py \
      --input <输出目录>/decision_tree.mmd \
      --output <输出目录>/decision_tree.png \
      --width 1400 --height 1000
    

Embed image references in the Markdown report:![图名](文件名.png)

Output Format

The output directory contains:

  • 1 Markdown report, including:
    • Risk Overview (traffic light summary table)
    • Key Findings and Recommendations (narrative style)
    • Risk Panorama (4 charts + introductory text)
    • Risk Scenario Analysis (scenario simulation)
    • Action Plan (including responsible departments and recommended timelines)
    • Appendix (formulas, complete calculation process)
    • Image references (![图名](文件名.png))
  • 4 PNG images:
    • risk_radar.png — Risk radar chart (generated with matplotlib, including colored band background and level labels)
    • risk_matrix.png — Risk matrix four-quadrant chart (generated with matplotlib, all-Chinese labels)
    • impact_pathway.png — Impact path directed graph (Mermaid graph TD, simplified node and edge labels)
    • decision_tree.png — Decision tree (Mermaid graph TD, yes/no question-and-answer format)

Dependencies

Tool Purpose Installation Method
matplotlib Radar chart and risk matrix rendering pip3 install matplotlib
numpy Radar chart colored band rendering pip3 install numpy(usually installed with matplotlib)
mmdc (mermaid-cli) Mermaid diagram rendering (impact path diagram, decision tree) npm install -g @mermaid-js/mermaid-cli
Chrome/Chromium mmdc's browser backend Built into macOS or installed manually

Key Rules

Client-oriented rules

  1. Target readers: The main body of the report is aimed at legal professionals and business decision-makers; terminology uses full Chinese names, and engineering abbreviations are not used
  2. Narrative first: Key findings are described in complete paragraphs, avoiding the piling up of large numbers of tables
  3. Tellability: Section 1 + Section 3 of the report should be able to support a 5-minute oral briefing to the business department on the core risks
  4. Scenario-driven: Each key path must be transformed into a specific scenario simulation to help non-legal professionals understand the logic of risk transmission

Data integrity rules

  1. Single source of truth: The third layer (impact path diagram) is the only data source; the data of the other three layers must be derived from the third layer
  2. Transparent calculation: The calculation of the risk index and transmission risk value must fully show the process (placed in the appendix)
  3. Radar chart calibration: Radar chart scoring must use the anchor table for calibration and must not be scored by feel

Causality rules

  1. Confidence annotation: Low-confidence causal relationships must be marked with dashed lines and noted as "to be confirmed"
  2. Implicit causality marking: All implicit causal relationships must be marked in the appendix with the pattern type and confidence level
  3. Explicit first: Prioritize explicit causality, with implicit causality as a supplement

Visualization rules

  1. All Chinese: All chart labels, axis labels, and legends must be in Chinese, and English must not appear
  2. Unified color scheme: All charts use a unified traffic light color system (green/yellow/red/blue/gray)
  3. Key path highlighting: Key paths in the impact path diagram must be shown in bold/changed color
  4. Node coloring: Use corresponding colors to distinguish by node type (red/blue/orange/purple)
  5. Legend description: A Chinese legend description must be attached below each chart

Decision rules

  1. Yes/no Q&A: The decision tree uses a yes/no question format and does not use numerical thresholds
  2. Action recommendations: Must be sorted by urgency, including the responsible department and recommended time limit
  3. Prioritize controllable nodes: Action recommendations should prioritize intervenable nodes, especially intervenable nodes on the critical path

References

Example

For the complete end-to-end case, see references/case-example.md。

This case demonstrates the entire process from the original legal analysis text of a "technical service contract dispute," through a 7-step workflow, to generating a risk visualization report containing 7 nodes, 2 paths, and complete four-layer output.