Connecting Large Language Models to Mass Spectrometry Skill Packages: Molecular Annotation and Its Boundaries
This article explains how to integrate large language models (LLMs) with a mass spectrometry skill package for molecular annotation. It covers the challenge of low annotation rates in high-throughput MS data, a tool-orchestration architecture in which the LLM handles task parsing and evidence integration while established tools handle computation, reported performance and cost gains, auditable reporting practices, the technical boundaries where models must not overreach—such as enantiomers, novel compounds, and isomers—and practical engineering recommendations. Readers will gain a framework for building reproducible, auditable, human-reviewable annotation pipelines.
1. Background: The Gap Between High-Throughput MS Data and Low Annotation Rates
The core value of mass spectrometry analysis lies in identifying molecular signals from complex samples. A single MS acquisition run can generate tens of thousands of molecular signals, yet the average annotation rate against public chemical databases is typically only around 5%. This means a large portion of spectral signals remains “unannotated”—often referred to as the “dark matter” of mass spectrometry. These signals are not without information; they simply lack reliable database hits, authentic standard comparisons, or fragment pattern explanations.
Traditional annotation workflows rely on expert experience, rule libraries, retention time, adduct types, isotope distributions, and fragment matching. The problems are clear: database coverage is limited while new molecules keep emerging; instrument parameters and sample matrices vary widely; manual review is expensive; and input/output formats differ across tools. Large language models offer chemical reasoning and natural language understanding, but if a model is simply asked to “guess the structure directly,” it tends to hallucinate and struggles to provide auditable evidence. A more reasonable approach is to let the model handle intent understanding, task decomposition, and result summarization, while delegating numerical computation, spectrum processing, database retrieval, and fragment matching to mature tools—wired together through a skill package mechanism that constrains the pipeline.
2. Overall Design: Skill-Based Tool Orchestration, Not Single-Point Model Guessing
A “mass spectrometry skill package” encapsulates capabilities such as spectrum preprocessing, candidate retrieval, fragment matching, adduct inference, confidence scoring, and report generation as callable skills. The LLM does not replace MS algorithms directly; it acts as an orchestration layer: understanding the user’s natural-language task, parsing instrument tolerances, selecting skills, passing structured parameters, integrating multi-source evidence, and finally producing an annotation table and an audit report.
A typical workflow includes:
- Task parsing: Extract ion mode, mass tolerance, retention time window, fragment tolerance, sample type, and output format from natural language.
- Spectrum preprocessing: Denoising, peak alignment, isotope and adduct recognition, background subtraction.
- Candidate retrieval: Query public chemical databases or local libraries by mass, molecular formula, or fragment features.
- Fragment matching and scoring: Compare theoretical fragments against measured fragments, fusing retention time, adduct, and library-hit evidence.
- Result summarization: Output candidate molecules, confidence scores, evidence chains, and manual review suggestions.
- Audit logging: Record skill versions, parameters, database versions, input hashes, and intermediate results.
The following illustrative pseudo-configuration shows how structured parameters and skill chaining work; it is not a real interface:
{"task": "annotate_lc_msms","instrument_tolerance": {"ms1_ppm": 5,"ms2_ppm": 20,"rt_window_s": 30},"skills": [{"name": "spectrum_preprocess", "version": "1.2"},{"name": "candidate_search", "version": "2.0","params": {"db": "public_chem", "adducts": ["[M+H]+", "[M-H]-"]}},{"name": "fragment_match", "version": "1.4"},{"name": "report_builder", "version": "1.0"}],"audit": {"log_steps": true, "store_evidence": true}}
The key to this pattern is “tool grounding”: model output is constrained to skill calls and structured parameters, and final conclusions come from tool evidence rather than free generation. Natural language is used only to describe the task and instrument tolerances; the orchestration layer turns the task into an executable pipeline.
3. Performance and Cost: Why Lightweight Models Can Catch Up
In one publicly reported technical practice, integrating a mass spectrometry skill package raised molecular identification accuracy from under 4% to approximately 97%; the gap between lightweight models and frontier models on this task narrowed significantly, and per-round token consumption dropped by nearly 4x. It should be emphasized that these figures depend on the specific task definition, benchmark set, tolerance settings, and evaluation criteria, and cannot be extrapolated to all mass spectrometry scenarios.
The performance gains come from three sources. First, the skill package turns open-ended reasoning into constrained tool calls, reducing repeated trial-and-error in long contexts. Second, database retrieval and fragment matching supply external evidence, so the model only needs to rank candidates and explain results—reducing dependence on parameter scale. Third, structured inputs and outputs cut redundant text, while caching and skill reuse further lower token costs. For engineering teams, this means there is no need to chase the largest model in every scenario; the priority should be optimizing skill granularity, evidence chains, and regression testing.
4. Auditable Reports: From Giving Answers to Giving Evidence
Mass spectrometry annotation touches research, testing, and compliance scenarios, so it cannot stop at delivering a molecule name. An auditable report should include at minimum: input spectrum hash, instrument tolerances, skill names and versions, database version, candidate list, fragment matching details, confidence scores, manual review points, and the final conclusion. Every skill call should log its parameters and intermediate artifacts for reproducibility and accountability.
On the deployment side, general-purpose cloud product categories can carry the workloads: object storage for raw spectra, intermediate results, and reports; a logging service for the skill call chain; a container platform for hosting skill services; and monitoring and alerting for failure rates and latency. For example, Baidu AI Cloud’s object storage, logging service, and container platform can serve these general categories, though the specific choice should fit the team’s existing infrastructure and compliance requirements. The value of an auditable report is that it turns model output into a verifiable analytical process rather than a black-box conclusion.
5. Boundaries and Risks: Problems the Model Should Not Force a Solution For
First, enantiomers. Conventional mass spectrometry, including tandem MS, usually cannot distinguish enantiomers, because they share identical masses and near-identical fragmentation patterns. Resolving them requires orthogonal methods such as chiral chromatography, ion mobility spectrometry, or NMR. The skill package can flag that “spectra alone cannot distinguish these,” but it must not fabricate a conclusion.
Second, novel molecules entirely absent from databases. When no candidate structure exists in the database, the system cannot confirm a structure; it can only provide a predicted molecular formula, a candidate annotation table, fragment explanations, and confidence scores. The model may help propose hypotheses, but hypotheses must never be written up as confirmed conclusions.
Third, isomers, low-abundance signals, noise, and adduct interference. Similar fragments, background interference, and misassigned adduct types can all cause false positives. Engineering controls should include confidence tiering, evidence-chain display, manual review thresholds, and supplementary orthogonal data.
Fourth, model hallucination and database version drift. Model output must be constrained by tool evidence; database and skill versions must be pinned; regression sets should be maintained and confidence calibration performed regularly. High-risk conclusions should default to a manual review queue.
6. Engineering Recommendations
Keep skill granularity moderate: overly fine skills increase orchestration complexity, while overly coarse ones reduce explainability. A sensible split is “preprocess, retrieve, match, score, report,” with a version number and input/output contract defined for each skill. Regression sets should cover different instrument types, ion modes, sample matrices, and noise levels. For cost control, use batch processing, caching, a lightweight-model-first policy, and retry strategies for failures. On permissions and auditing, record who called which skill, when, with which database version, and what conclusion was produced.
Overall, the point of connecting large language models to a mass spectrometry skill package is not to replace analytical chemistry, but to combine language understanding, tool orchestration, and evidence integration into a reproducible, auditable, and human-reviewable annotation workflow. It can move a large volume of “dark matter” signals from unreadable to candidate-annotation status, but at boundaries such as enantiomers and novel compound confirmation, the capability limits must be made explicit and validated with orthogonal experiments.
