Construction of graph neural network for medical AI legal knowledge graph
As shown in Figure 1, the proposed framework comprises three main modules. The input layer integrates multi‑source data into a heterogeneous graph via multimodal entity encoding and directed edge modeling. The relation‑aware GCN layer then performs cross‑modal semantic alignment through type‑specific weights and attention, producing unified node embeddings. Finally, these embeddings support bias tracing (via gradient backpropagation and community detection) and dynamic compliance monitoring (via real‑time node mapping and edge‑weight tracking), with the output delivering interpretable attribution evidence and risk alerts for regulators.

Figure 1: Legal knowledge graph and bias tracing architecture for medical AI. This diagram illustrates the overall workflow of the proposed framework. The input layer fuses multi‑source heterogeneous data (legal texts, clinical guidelines, algorithm audit reports), which are encoded into four entity types (legal clauses, medical behaviors, algorithm modules, responsible parties) and connected by four directed legal‑semantic relations (violation, basis, trigger, attribution). The relation‑aware GCN layer performs cross‑modal semantic alignment via type‑specific weights and attention. The bias tracing module uses gradient backpropagation to identify high‑contribution edges, then applies community detection to locate root‑node clusters. The dynamic compliance monitor maps real‑time decisions to temporary nodes, evaluates embedding similarity against legal clauses, and tracks edge weight evolution for early warning. Outputs include interpretable attribution evidence and risk alerts. Please click here to view a larger version of this figure.
Heterogeneous graph structured coding of legal entities and relationships
Four fundamental entities are consistently derived from medical AI regulatory laws, clinical practice guidelines, and algorithm audit reports: legal clauses, medical procedures, algorithm modules, and accountable entities. A separate feature representation learning model is proposed for each type of entity to be semantically distinguishable. The legal clause nodes are organized to contain the number of the legal clause, and this is used as a unique ID (identifier) for the legal clause. At the same time, a penalty severity quantification index is defined to indicate the level of legal responsibility associated with the clause, and consequently, a feature vector is established.
(1)
ci is the entry number, Emb(·) represents the low-dimensional embedding mapping, and [·;·] represents the vector concatenation operation. This representation preserves both the formal structure and the severity of punishment of the legal text, supporting cross-statement reasoning.
Medical behavior nodes are standardized and encoded based on a clinical operation classification system, extracting their risk level rj ∈ {1,2,3} and the set of applicable scenario labels sj ⊂ S, where S is the complete set of predefined scenario categories. Multi-hot encoding is used to process the label set, and it is concatenated with the risk level embedding to form an initial representation:
(2)
This strategy ensures that different types of medical behaviors have measurable distance relationships in the vector space, supporting cross-scenario comparisons. The text embedding function Emb(·) is implemented using the pre-trained Chinese legal language model Lawformer (pretrained on a large-scale Chinese legal corpus), with the output dimension fixed at 768.
Based on the logical dependencies and legal constraints between entities, four types of directed semantic relationships are established: "violation", "basis", "trigger", and "attribution", each corresponding to different legal causal patterns. Each edge eij ⊂ E is assigned a type of label tij ⊂ T = {violate, base, trigger, attribute} for subsequent message transmission for relationship awareness. Edge construction strictly follows the domain rule matching mechanism: when a medical behavior deviates from the normative requirements, a "violation" edge is established pointing from the behavior node to the relevant legal clause; when the legal clause serves as the technical compliance basis for an operation, a "basis" edge is established; if the output of the algorithm module directly triggers the execution of a specific medical behavior, a "trigger" edge is connected; the attribution of responsibility relationship is established based on the organization's responsibility documents and audit conclusions, establishing an "attribution" edge between the responsible party and the violation or algorithm defect.
After all nodes are initialized, a heterogeneous graph (V, E, H0) is formed, where V is the set of nodes, E is the set of directed edges with type labels, and H0 is the initial feature matrix. To enhance the semantic discriminative ability of the graph structure, the node features are normalized:
(3)
μk and σk are the mean and standard deviation of the k-th node feature on the training set, respectively, and ∈ is a small constant to prevent division by zero. Normalization ensures that multi-source heterogeneous features participate in graph convolution operations on a uniform scale, preventing numerical dominance effects from interfering with semantic learning. The resulting structured graph model fully carries the relational topology of the four-dimensional elements of law, behavior, technology, and responsibility in the medical AI system, providing a computable graph basis for subsequent bias propagation analysis.
Graph convolution alignment enhancement for cross-modal legal semantics
A relation-aware graph convolutional network38,39, which extends the Relational Graph Convolutional Network (R-GCN) framework, is used to propagate features across multiple layers of the initial heterogeneous graph. While R-GCN introduces per-relation transformation matrices for general relational data, our approach further incorporates a learnable attention mechanism to dynamically weight neighbor contributions and defines four specific legal-semantic relation types (violation, basis, trigger, attribution) tailored to medical AI compliance analysis.. Each layer's operation independently parameterizes the transformation process based on the semantic type of the edges. For any target node, its neighborhood information is grouped and aggregated by the types of connecting edges. Each type of relation is equipped with a dedicated linear transformation matrix to differentiate the features transmitted along different legal semantic paths40,41. If the edge between the legal clause node and the medical behavior node is of "base" type, when the legal clause node receives a message from a medical behavior node, it applies the corresponding weight matrix to map the features of the neighbor spatially. In the same way, when a medical behavior node sends an output via the edge integration scheme module node "trigger" to an algorithm module, the parameter matrix triggered, associated with this relation, and performs feature transformation. This mimics the fluidity of different types of legal logic, realizing/informing different logic layers to maintain semantic independence during information flow without cross-modal noise. The aggregation is defined as follows:
(4)
mi(l) represents the comprehensive information collected by node i in layer l, Nil is its neighbor set under relation r, Wr is the linear transformation matrix, and hj(l−1) is the embedding representation of the neighbor node in the previous layer.
A learnable attention mechanism is introduced during message aggregation to dynamically adjust the influence intensity of different neighbor nodes on the target node representation update42,43. The attention coefficient is generated based on the dual factors of node attribute similarity and legal importance, without relying on fixed prior weights. For legal clause nodes, when receiving neighboring medical behavior features, the attention score is calculated based on the quantified value of the penalty intensity associated with the latter; when the algorithm module node fuses medical behavior information, it focuses on neighbors with higher operational risk levels. The attention weight is calculated in the following way:
(5)
αij is the attention coefficient of node j to node i, and a is the learnable attention vector. This model allows for the automatic identification of high-risk or high-constraint connected paths during end-to-end training, assigning them higher attention. The final updated node embedding is determined by weighted messages and residual connections.
(6)
σ is the activation function, and residual design mitigates the gradient vanishing problem in deep propagation and guarantees stability in the presence of multiple semantic conflicts. Following L = 3 graph convolutional layers (each with a hidden dimension of 256 and ReLU activation), the embeddings of all nodes seamlessly incorporate cross-modal contextual information and become unified representations with legal semantic discrimination abilities.
Two alternative legal compliance analysis diagrams for the healthcare AI are depicted in Figure 2, with the objective of addressing the visualization of types of legal relationships and routes for bias propagation, indicating potential bias sources of this decision-making. Figure 2A displays the influence of various legal semantic relations, where four relation types are color-coded, and for each type the edges are distinguished by a different color. The thickness of the edge corresponds to the attention weight of that particular relation, i.e. how much this relation contributes to the AI decision. A thick edge indicates essentially a dominant legal relation in the decision and in this case it sufficiently motivated the outcome of the case. Node size is measured by its contribution to violations: larger nodes signify a stronger relationship between the conduct and specific legal clauses, and hence higher potential risk. The above visualization provides a crisp legal semantic layer, which enables us to identify the strongest and riskiest legal paths in AI decision-making. Figure 2B also indicates high-contribution paths (to bias propagation) with emphasis on edges with high contributions, which are bolded and accompanied by dashed lines (e.g. B1-B3) in the decision-making process. Doubling of the width of these edges represents their importance in disseminating systemic bias. Which combinations of legal rules and technical behaviors result in this amplification effect for bias is shown in Figure 2. This analysis not only discloses the path of bias propagation, but also facilitates identifying the origin of bias, based on which compliance auditing and responsibility of the AI tool can be established.

Figure 2: Analysis of legal compliance and bias propagation in healthcare AI (Illustrative Example). (A) Color‑coded legal semantic relations: violation (red), basis (blue), trigger (green), attribution (orange). Edge thickness is proportional to attention weight, indicating the influence of each relation on the AI decision. Node size is proportional to its violation contribution, highlighting risky entities. (B) Bias propagation subgraph: high‑contribution edges are bolded and dashed (e.g., B1‑B3); double‑width edges indicate amplification of systemic bias. This visualization supports identification of dominant legal paths, bias origins, and compliance auditing. No measurement scales or error bars are applicable as this is a schematic illustration. Please click here to view a larger version of this figure.
Subgraph backtracking mechanism for bias propagation path
In this study, "bias" is defined as the systematic deviation of an AI system's output from the clinically and legally expected decision, measured by the discrepancy between the model's predicted risk score and the ground-truth compliance label. The bias signal is quantified as the cross-entropy loss between the algorithm's final output and a binary indicator of compliance (1 for compliant, 0 for non-compliant), aggregated over all decision instances in a batch.
After the graph neural network is trained, its differentiability is used to perform backpropagation analysis on the bias signal in the output layer. Starting from the algorithm decision node that detects anomalies, the gradient magnitude of the loss function with respect to each connecting edge is computed to quantify each edge's contribution to bias formation. This process is implemented through an automatic differentiation framework, backtracking layer by layer along the directed edges in the graph structure to obtain the influence strength of each edge parameter transformation on the final output change. The higher the absolute value of the gradient, the more dominant the legal-technical relationship carried by that edge is in the bias propagation. The contribution of an edge is defined as:
(7)
Lbias is the differentiable loss defined for biased behavior, and wi is the entry weight vector corresponding to the edge type. This gradient value reflects the degree of participation of a specific semantic relationship in the current association bias. After all edges are scored in this way, a dynamic threshold τ is set to filter out the set of high-contribution edges Ehigh whose contribution exceeds gij > τ, forming the initial bias propagation subgraph Gbias = (Vbias, Ehigh). Specifically, τ is determined as the 85th percentile of the absolute gradient values across all edges in each training epoch, ensuring that only the top 15% most influential edges are retained for subgraph construction. This subgraph focuses on the key connection paths most likely to drive systematic bias, compressing the search space and improving the efficiency of source tracing.
Within the constructed bias-propagation subgraph, a spectral clustering-guided community detection algorithm is executed to identify highly in-line node cluster structures. This process is based on the normalized Laplace matrix factorization of the subgraph, mapping node embeddings to a low-dimensional spectral space and applying a density-aware clustering strategy in this space to ensure that cross-type nodes (such as legal clauses and algorithm modules) are grouped into the same cluster when functionally closely related. Each identified community represents a potential functional loop or responsibility aggregation unit. The community partitioning results are driven by the following optimization objectives:
(8)
L=D−A is the Laplacian matrix of the subgraph, A is the adjacency matrix, D is the degree matrix, ck is the indicator vector of the k-th community, and K is the preset number of communities. This criterion maximizes the minimum cut difference between communities, ensuring tight internal connections.
Now, cross-layer composite-based analysis is carried out on each community. If a community has legal clause nodes and algorithm module nodes, it is tagged as a potential source of bias. To test its causality, an intervening test is conducted: all edges in this region are removed temporarily from the graph, the same decision-making process is executed again, and differences in bias measurements are noticed. The causal validity measure is defined as:
(9)
Borig and Bmask represent the bias strength of the original model and the bias after masking, respectively. If the causal validity measure is substantially above the predetermined threshold, it implies that the node cluster has been identified as an explainable source of bias, which will guide later compliance correction and fault assignment.
Dynamic compliance verification of legal constraints
Real-time decision instances appearing during the operation of a medical AI system are introduced as transient nodes and embedded in a learned knowledge graph space. An initial feature vector is produced by each node by reading its input context, output behavior, and the algorithm's state. Then, this vector is fed into a graph neural network with frozen parameters to perform one-layer forward propagation, yielding an embedding aligned with the knowledge graph without altering the original graph structure. As such, it allows transient nodes and legal clause nodes to be compared in a common semantic space.
Then compute the cosine similarity between the transient node and each of the legal clause nodes:
(10)
htemp is the embedding of the temporary node, and hjlaw is the embedding of the j-th legal clause node. The similarity value virtually reflects the semantic matching degree between the current decision and each legal constraint. A dynamic compliance threshold θ is set based on the similarity distribution of historical compliance samples to adapt the judgment boundary under different application scenarios. Specifically, θ = µ - 2σ, where µ and σ are the mean and standard deviation of the cosine similarity distribution computed from a validation set of 500 known compliant decision instances.
If a cosine similarity score falls below the dynamic compliance threshold, the corresponding rule of law is considered violated, triggering the compliance alerting mechanism. The notification also includes the minimal matching legal clause number, the similarity value, and the direction of the divergence analysis, which should be sufficient for the regulators to act promptly. This approach provides an interpretable mapping from opaque decision-making to the space of legal semantics and facilitates on-the-fly compliance checking.
During continuous operation, the weight-change trend of key legal-technology connection edges in the bias propagation subgraph is tracked. Emphasis is placed on the edges connecting algorithm module nodes and legal clause nodes, as they directly represent the response strength of technical behavior to specific regulations. The transformation matrix parameters for each target edge are recorded during the inference, and their norm is extracted as a dynamic indicator of the evolution of the correlation strength between the two. Defining the edge strength sequence as:
(11)
wt represents the Frobenius norm of the weight matrix corresponding to the relationship between edge eij at time stamp t, and Wkl(t) is the parameter matrix actually used in the model at that time. This indicator reflects the model's learning depth or dependence on the legal constraint.
A sliding-window monotonicity test is performed on the sequence, and an improved sign test is used to determine whether a significant upward trend is observed. If the increments over N consecutive time steps satisfy the positive dominance condition, then the edge is considered to exhibit an abnormal reinforcement phenomenon. Further combining historical gradient contribution data, if the edge has been identified as a high-impact path in the previous round of source tracing analysis, a systemic bias accumulation early-warning process is initiated.
Finally, a source-tracing report is generated, including information on the nodes at both ends of the target edge, weight change curves, statistics on the frequency of related decisions, and potential attribution recommendations. This mechanism realizes a leap from static compliance judgment to dynamic risk prediction, supporting proactive intervention in potential institutional deviations.
Experimental data and design
To verify the effectiveness of the proposed framework, this paper constructs a multi-source heterogeneous dataset that integrates real regulations and simulation data and designs rigorous control experiments. Data sources include national medical AI regulatory regulations, clinical treatment guidelines, open-source algorithm audit reports, and simulation decision logs. After preprocessing, a benchmark heterogeneous knowledge graph containing 285 nodes (85 legal clauses, 120 medical behaviors, 42 algorithm modules, and 38 responsible entities) and 1247 directed edges is constructed, as shown in Figure 3.

Figure 3: Distribution and characteristics of heterogeneous entity types. (A) Bar chart showing the number of nodes for each entity type: legal clauses (85), medical behaviors (120), algorithm modules (42), responsible parties (38). (B) Histogram of penalty intensity for legal clause nodes, binned into low (0‑0.33), medium (0.34‑0.66), and high (0.67‑1.0) categories; the vertical axis represents count. (C) Pie chart of risk level distribution among medical behavior nodes: low (19%), medium (43%), high (38%). All values are absolute counts or percentages; no error bars are presented because these are descriptive statistics of the dataset. Please click here to view a larger version of this figure.
Figure 3 illustrates the distribution and characteristics of entity nodes in the heterogeneous knowledge graph. Figure 3A shows the distribution of the number of four types of entity nodes, with "medical behavior" nodes being the most numerous (120), followed by "legal clauses" (85), while "algorithm modules" (42) and "responsible entities" (38) are relatively fewer. This is because the graph is structurally designed based on behavior and rules. Figure 3B presents the distribution of penalty intensities for nodes representing a unique legal clause, where intensity measures the severity of the legal liability. The data indicates that there are relatively few provisions with high penalty intensity, and most are in a medium-to-low intensity bracket, which is consistent with the reality that there are only a few severe violation clauses in real-world legal systems. Figure 3C illustrates the distribution of risk level in medical behavior nodes, where medium risk behaviors have the largest proportion 43% while low risk behaviors have the lowest proportion 19%, which reveals that medical scenarios are normally operated, and high-risk operations are subjected to more rigorous association constraints in the graph. These statistics collectively justify the entity disambiguation encoding scheme adopted in knowledge graph construction to provide feature support for subsequent graph convolutional alignment.
The entire dataset was randomly partitioned into training (70%), validation (10%), and test (20%) sets, stratified by node type and relation distribution to preserve the overall graph structure in each split. The same partition was used consistently for all baseline methods to ensure a fair comparison. In addition to this base partition, the three knowledge graph density gradients (sparse, medium, dense) and the three cross-jurisdictional complexity settings (single, bilateral, multilateral) described above serve as independent practical testbeds, that collectively evaluate the method's robustness under varying data completeness and regulatory overlap conditions. To construct ground-truth labels for bias localization evaluation, we adopted a two-step strategy: (1) Expert annotation—three legal and medical experts independently reviewed the decision logs and identified the root cause nodes and propagation paths for each recorded compliance violation, with discrepancies resolved by majority vote; (2) Simulated injection—for controlled testing, we artificially injected bias signals into 20 randomly selected decision paths by perturbing the edge weights in the knowledge graph, ensuring that the true source nodes and affected edges were known a priori.
For all baseline methods (TransE, ComplEx, Graph Neural Networks (GNN) Explainer, KG-BERT, and Node2Vec), we used the same training configuration (Adam optimizer, learning rate 1 × 10−3, batch size 64, 100 epochs) and the same data partitions as our method to ensure a fair comparison. For TransE and ComplEx, the embedding dimension was set to 256 with a margin of 1.0; for KG-BERT, we used the pre-trained BERT-base model with a batch size of 16 and a maximum sequence length of 128; for GNNExplainer, we used a 3-layer GCN with the same hidden dimension of 256; and for Node2Vec, we set the walk length to 80, the number of walks per node to 10, and the embedding dimension to 256.
To ensure a fair comparison, we adapted all baseline methods to the same bias localization tasks, namely root‑node identification and propagation‑path reconstruction. For TransE, ComplEx, and Node2Vec, which are not inherently explainable, we computed the gradient of the bias loss with respect to each node’s embedding and used the gradient magnitude as the node importance score; root nodes were selected by thresholding these scores, and propagation paths were reconstructed by retaining edges with the highest gradient contributions. For GNNExplainer, we directly used its built‑in edge‑importance and node‑mask mechanisms to obtain both root nodes and subgraphs. For KG‑BERT, which operates on triplets, we converted each graph edge into a textual triplet and used the model’s attention weights over entities to derive node importance, followed by the same thresholding strategy for path reconstruction. Through these adaptations, every baseline method produces both root‑node predictions and propagation‑path predictions, enabling a uniform evaluation across all methods.
The evaluation is centered around four fundamental capabilities: accuracy of semantic alignment, ability to localize bias, efficiency of accountability, and generalization across domains. It also presents three important control variables, mimicking real-world complexity.
1) Knowledge graph density gradient: To assess how the method performs at varying completeness levels of information, two subsets from the baseline full graph (density D = 1.0) are created based on a random edge discarding strategy as follows:
Sparse graph (D ~ 0.3): 30% of edges are retained randomly, simulating the stage of early knowledge construction with much information missing.
Medium-density graph (D ~ 0.6): 60% of edges are retained randomly, simulating a typical scenario of partially known knowledge structure.
Dense graph (D = 1.0): Using all 1247 edges, corresponding to a best-case scenario of relatively complete knowledge.
2) Medical AI decision frequency situation: Three artificial decision flow loads are set to test the real-time performance of dynamically compliance monitoring:
Low frequency 10 Hz: On average, 10 decision events are generated per second, simulating monitoring of small-scale or single-site systems.
Medium frequency 50 Hz: 50 decision events per second simulating the AI system load of regional or medium-scale medical institutions.
High frequency 100 Hz: 100 decision events per second simulate the high concurrency pressure scenarios for the AI services being deployed in a large hospital or cloud platform.
3) Cross-juridictional complexity gradient: To test the transferability of legal constraint modelling, three complexity-based test sets were constructed:
Single jurisdiction: Consists solely of current Chinese laws and regulations governing medical AI.
Bilateral jurisdiction: Incorporates the regulatory regimes of China and the European Union, with around 15% of the rules being conflicting and overlapping.
Multilateral jurisdiction: Building upon the first two, it further integrates privacy and security rules from the US HIPAA (Health Insurance Portability and Accountability Act), creating a test environment in which the legal systems of the three legal regimes intertwine, increasing the rule conflict rate to approximately 25%.
The following key indicators were used for quantitative evaluation:
1) Semantic alignment accuracy: Measures the graph's ability to model the relationships between legal and technical entities.
Entity alignment accuracy:
(12)
Ppred is the set of aligned entity pairs predicted by the model, and Pgold is the set of golden alignments annotated by experts.
Relation preservation integrity:
(13)
Rgraph is the reconstructed set of relations in the graph, and Rtext is the set of explicit relations extracted from the original legal text.
2) Bias Localization Ability: Evaluating the effectiveness of tracing the root causes and propagation paths of bias.
Root Node Recall Rate:
(14)
Npred is the set of bias source nodes identified by the model, and Ntrue is the set of true source nodes labeled by experts.
Propagation path accuracy:
(15)
Epred is the edge set in the bias propagation subgraph inferred by the model, and Etrue is the true bias propagation edge set.
3) Accountability Tracing Efficiency: Test the system's performance in real-time monitoring scenarios.
Average Tracing Latency:
(16)
M represents the total number of requests, and titrigger and tireport are the timestamps of the i-th bias trigger and the generation of the source report, respectively.
System throughput:
(17)
Nprocessed represents the number of concurrent tracing requests successfully processed within the time window ΔT.
4) Cross-domain generalization ability: Verifying the adaptability of the method to different legal systems.
Jurisdictional coverage:
(18)
Cencoded represents the number of different jurisdictional clauses successfully encoded into the graph, and Cinput represents the total number of input clauses.
Constraint conflict detection rate:
(19)
Dpred is the set of legal logic contradictions detected by the model, and Dgold is the set of all contradiction pairs annotated by experts.
All experiments were conducted using a workstation equipped with a multicore processor and a graphics processing unit; complete hardware specifications are provided in the Table of Materials.
The main hyperparameters of this approach and their values are listed in Table 1, encompassing model structure and training configuration as well as crucial thresholds, such as embedding dimension, number of convolutional layers, learning rate, and batch size. All the parameters were tuned with respect to the validation set through grid search, the trained model has stably converged, and the performance is best. Some thresholds are established together with domain criterion to fulfill the requirements of high reliability of medical AI compliance checking.
| Parameter | Value | Description |
| Embedding Dimension | 128 | Feature dimension size for node embeddings |
| Number of Convolution Layers | 3 | Depth of the relation-aware graph convolution network |
| Learning Rate | 0.001 | Initial learning rate for Adam optimizer |
| Batch Size | 32 | Number of subgraphs processed per batch |
| Dropout Rate | 0.1 | Dropout probability applied to node features during training |
| Number of Attention Heads | 8 | Number of heads in multi-head attention mechanism |
| L2 Regularization Coefficient | 5 × 10⁻⁴ | Weight decay coefficient for parameter regularization |
| Similarity Threshold | 0.75 | Minimum embedding similarity for compliance validation |
| Gradient Contribution Threshold | 0.01 | Threshold for selecting high-impact edges in bias subgraph construction |
| Monitoring Window Size | 10 | Time steps used for tracking edge weight dynamics |
Table 1: Main parameter settings. List of key hyperparameters used in the experiments: embedding dimension (256), number of GCN layers (3), hidden dimension (256), learning rate (1 × 10−3), batch size (64), attention vector dimension, edge contribution threshold (85th percentile of gradient magnitudes), dynamic compliance threshold (µ‑2σ, where µ and σ are from the validation set of 500 compliant instances), number of communities K (determined by spectral clustering), and optimizer (Adam). These values were selected via grid search on the validation set.