I. Introduction
II. Methods
1. Case Collection, Exclusion, and De-identification
2. Chain-of-Thought Pipeline Development
- Step 1 (Clinical context generation): The counseling request was first analyzed to extract clinical keywords using an initial prompt, followed by a second prompt elaborating on these keywords to provide general background information. This step constructed a clinical context without interpreting or prematurely expanding on the patient’s specific claims, which were subsequently addressed in later pipeline steps.
- Step 2 (Legal issue identification): The counseling request was analyzed to identify potential malpractice-related legal issues. Building upon prior research, such as that by Wu et al. [2], who classified clinical errors into diagnosis, intervention, and management categories, the present study expanded these categories based on prior literature [19,20] into 10 malpractice categories—diagnosis and examination, medication and prescription, injection, anesthesia, surgery, hospital transfer, infection control, safety management, informed consent, and patient monitoring. Each malpractice category had its own dedicated prompt functioning as a filter to assess applicability to the counseling request. Outputs included a binary flag (1 for applicable, 0 for not applicable) and a concise rationale (Figure 2). Few-shot examples guided the chatbot’s reasoning across diverse cases. Categories flagged as applicable were subsequently passed to the Legal Issue Elaboration step, with their rationales removed.
- Step 3 (Legal issue elaboration): Categories identified as applicable (flag = 1) proceeded to this step, with initial rationales removed to prevent premature assumptions of malpractice. A distinct prompt further elaborated each flagged category as a legal issue, striving to minimize assumptions. This two-step process enabled the pipeline to expand on legal issues while maintaining a more neutral perspective.
- Step 4 (Preliminary response drafting): Utilizing the clinical context and legal issues identified in previous steps, this step combined information to draft a preliminary response. It organized overlapping information coherently to produce a comprehensive reply addressing the counseling request.
- Step 5 (Response refinement): In this final step, the preliminary response underwent refinement through three sub-processes: filtering, which removed irrelevant or inappropriate content; standardization, which aligned vocabulary usage across responses for consistency; and tone randomization, which adjusted the response’s tone by emulating a randomly retrieved human response from the development dataset, used as a reference.