LLM-Driven Mass Spectrometry Analysis: Tool Orchestration and Trustworthy Annotation Practices

    This article explains how large language models can support mass spectrometry analysis without replacing measurement. It covers the core problem of abundant signals but weak structural evidence, the proper role of LLMs as analysis orchestrators, input normalization, layered evidence strategies from molecular formula to candidate structures, tool orchestration with explicit failure handling, correct interpretation of accuracy and cost, auditable reporting, capability boundaries, and a practical rollout path. Readers will learn how to build reproducible, evidence-centered workflows that distinguish confirmed identifications, candidate annotations, and undetermined cases.

    1. The Core Tension in Mass Spectrometry: Rich Signals, Weak Structural Evidence

    A mass spectrometer can produce a large number of ion signals in a single run, but “a signal was detected” is not the same as “a molecular structure was confirmed.” Going from raw data to a reliable annotation usually involves peak detection, noise filtering, isotope grouping, adduct recognition, molecular formula screening, candidate structure retrieval, and fragment matching. A deviation at any step can affect the final result.

    Three types of objects must be clearly distinguished: raw spectral peaks, merged analytical features, and distinct compounds. The same compound may form different adduct ions, may produce multiple fragments, or may recur across different scans. Tens of thousands of signals therefore cannot be interpreted directly as tens of thousands of distinct molecules.

    A large number of features cannot be assigned a reliable structural annotation, a situation often described as the “dark matter” of mass spectrometry. The causes are not a single algorithmic shortcoming but the combined effect of incomplete database coverage, inconsistent experimental conditions, similar molecular structures, and insufficient evidence quality.

    The reasonable technical goal is therefore not to have a model generate a plausible-sounding name for every signal, but to build an evidence chain that distinguishes “confirmed,” “candidate annotation,” and “not yet determinable.”

    2. The Proper Role of LLMs: Orchestrating Analysis, Not Replacing Measurement

    Large language models are good at understanding tasks, breaking down steps, calling tools, and explaining results. They are not suited to performing precise mass calculations, spectral similarity computations, or chemical structure confirmation from language knowledge alone.

    A more robust architecture is:

    natural-language task → structured analysis plan → specialized tool computation → database retrieval → evidence aggregation → human review.

    In this architecture, the LLM takes on the orchestration role:

    • Translating user needs into explicit analysis targets and constraints;
    • Deciding which computation or retrieval is needed next based on the available data;
    • Aggregating evidence and conflicts returned by different tools;
    • Producing an analysis report that includes uncertainty statements.

    Numerical computation, candidate filtering, and spectral matching should be delegated to validated algorithmic implementations. The chemical interpretations a model proposes should be treated as hypotheses to be verified, not automatically promoted to experimental conclusions.

    The value of this division of labor is that it reduces the cost of manually switching between multiple tools while preserving the determinism and reproducibility of the specialized computations.

    3. Normalize the Input Before Discussing Intelligent Analysis

    3.1 Establish a Verifiable Input Contract

    Users may describe a task in natural language, but the system must convert it into a structured configuration. The necessary information usually includes the ionization method, positive or negative ion mode, the precursor ion m/z, the mass tolerance, possible adducts, whether a fragment spectrum is available, and the relevant experimental conditions.

    If the user only says “analyze these peaks,” the system should not silently adopt unconfirmed assumptions. Missing conditions can change the candidate set, so gaps should be listed explicitly and the user asked to supply them; for fields where a default value can be used, the default and its basis should be stated in the report.

    The mass tolerance in particular needs an explicit unit. Relative mass error is commonly expressed in parts per million, calculated as:

    mass error = (measured value − theoretical value) ÷ theoretical value × 10⁶.

    This calculation must compare quantities with the same physical meaning. For example, the measured m/z of an ion must not be mixed directly with the theoretical mass of a neutral molecule. When adducts, charge states, or multiply charged ions are involved, the corresponding conversions must be completed first.

    3.2 Preserve Raw Data and Processing Records

    Peak extraction, denoising, and grouping change the objects of downstream analysis, so the processing algorithm, parameters, version, and execution time should be recorded. The raw files and the processed feature table should be stored separately, so that a system is not left with only a final annotation table and no way to trace back.

    For batch experiments, blank samples, quality-control samples, and replicate measurements should also be used to identify background contamination, signal drift, and low-stability features. An LLM cannot compensate through reasoning for missing experimental quality control.

    4. From Molecular Formula to Candidate Structures: A Layered Evidence Strategy

    4.1 Use Accurate Mass to Narrow the Molecular Formula Range

    Molecular formula inference usually starts from the accurate mass, then filters candidates using element ranges, isotope distribution, and chemical plausibility. Element constraints should come from the sample type and experimental context, not be tightened arbitrarily just to obtain fewer candidates.

    An accurate mass match is only a necessary clue, not proof of structure. Different molecular formulas may fall within the same tolerance window, and the same molecular formula may correspond to multiple structures.

    The output should therefore retain reasonable candidates and the reasons they were filtered, rather than showing only a single seemingly certain answer.

    4.2 Use Isotope and Adduct Relationships to Strengthen Judgment

    Isotope peak patterns can provide clues about elemental composition, and different adducts of the same feature can help infer the neutral mass. However, these judgments depend on signal intensity, resolution, and peak-grouping quality.

    The system should separately record “the observed relationship” and “the conclusion inferred from the relationship.” If the isotope peak has a low signal-to-noise ratio, the weight of that evidence should be reduced rather than forcing an ideal pattern onto it.

    4.3 Rank Candidate Structures Using Fragment Evidence

    Tandem mass spectrometry can provide fragment ions and neutral-loss information, which is usually more discriminating than using the precursor mass alone. Candidate ranking can jointly consider fragment mass matching, spectral similarity, coverage of key fragments, and consistency of experimental conditions.

    But different collision conditions and instrument settings change fragmentation behavior. When database spectra are inconsistent with the current experiment, “a certain peak was not matched” is not necessarily enough to rule out a candidate. A similarity score should also not be interpreted directly as the probability that a structure is correct, unless it has been independently calibrated.

    5. Tool Orchestration Should Have Clear Execution and Failure Mechanisms

    A complete analysis workflow should not rely on the model improvising on the fly. Developers can split the workflow into verifiable stages:

    1. Validate the input and experimental metadata;
    2. Extract, clean, and group the analytical features;
    3. Compute the mass error and candidate molecular formulas;
    4. Query reference data to obtain candidate structures and associated spectra;
    5. Perform fragment matching and evidence scoring for the candidates;
    6. Check for conflicts, gaps, and applicability boundaries;
    7. Output the annotation table and audit report.

    Each stage should define its input, output, timeout policy, and failure state. For example, when the retrieval service is unavailable, the result should be marked as “retrieval incomplete” and not treated as “the molecule does not exist in the database.”

    Text returned by tools should also be treated as data to be verified, not as instructions that can change the system’s execution rules. The model may read the chemical descriptions within it, but must not use arbitrary text in external records to expand permissions, perform extra operations, or bypass checks.

    For high-cost analysis, low-cost filtering can be run first, followed by in-depth interpretation of the retained candidates. Compared with placing all spectra and database content directly into the model context, this approach makes compute cost easier to control and is easier to audit.

    6. Correctly Interpreting Accuracy and Cost Data

    In specific tests, connecting tools may significantly improve a model’s molecular recognition performance, but a single percentage does not describe real-world effectiveness. Before discussing any accuracy figure, at least the following questions should be answered:

    • Are the test objects already included in the reference database?
    • Does the input contain a complete fragment spectrum, or only the precursor mass?
    • Is the evaluation target the molecular formula, the structure candidates, or a specific structure?
    • Is top-1 hit rate used, or coverage across the top several candidates?
    • Does it include isomers, low signal-to-noise samples, and unknowns outside the database?
    • Is the test set sufficiently isolated from the development or tuning data?

    “Selecting the correct structure among existing candidates” and “identifying a new structure outside the database” are tasks of different difficulty, and their metrics must not be mixed.

    Likewise, a lightweight model may achieve results close to a larger model in a workflow with clear constraints and sufficient tools, but this does not mean the two are equally capable across all chemical tasks. It more likely indicates that when the key computations and retrievals are handled by reliable tools, model size is no longer the only determining factor.

    Cost evaluation should also not look only at the number of model tokens; it should include tool calls, data transfer, retrieval time, failure retries, and human review. It is advisable to report accuracy, coverage, refusal rate, end-to-end latency, and total cost per sample together.

    7. An Auditable Report Should Let Conclusions Be Reviewed

    A reliable report should contain at least four groups of information.

    The first group is the input and conditions, including the sample identifier, data version, ion mode, mass tolerance, and the analysis parameters used.

    The second group is the candidates and evidence, including the candidate molecular formulas or structures, mass error, isotope matching, fragment matching status, and the source of the reference data.

    The third group is the process record, including tool versions, execution order, retrieval times, exception information, and any manual adjustments.

    The fourth group is the boundaries of the conclusion, including peaks still unexplained, conflicts between candidates, the current confidence level, and suggested additional experiments.

    The report should present “observed facts,” “computed results,” and “model interpretations” separately. In particular, language fluency must not be taken as evidence strength. For real business use, retaining a structured annotation table is usually more important than outputting only a summary paragraph, because the former can support downstream statistics, review, and version comparison.

    8. Define Capability Boundaries and Avoid Over-Confirmation

    Routine, non-chiral mass spectrometry conditions generally cannot reliably distinguish enantiomers from spectra alone. When needed, chiral separation or other discriminating experimental methods should be combined. For structurally similar candidates such as positional isomers, an ordinary fragment spectrum may also be insufficient to yield a unique conclusion.

    For molecules outside the reference database, the system can attempt to propose a molecular formula, substructure clues, or candidate hypotheses, but it must not state them as confirmed structures. Confirming an unknown structure usually requires more complementary evidence, such as comparison with reference standards, further fragmentation experiments, or other structural characterization methods.

    The most important engineering principle is to allow the system to explicitly refuse to make a single judgment. Reliable automation is not about giving every sample an answer, but about giving every answer evidence commensurate with it.

    9. Implementation Roadmap: Reproducibility First, Then Expand Automation

    In practice, you can start by establishing a baseline on tasks with stable experimental conditions and relatively sufficient reference data. Use manually reviewed samples to evaluate molecular formula screening, candidate ranking, and report generation, then gradually extend to complex samples.

    For deployment, object storage can hold raw data, a message queue can schedule batch tasks, containerized runtime environments can pin computation dependencies, and logging and monitoring can record failure rates and latency. This infrastructure can only improve workflow stability; it cannot replace chemical evidence validation.

    As data accumulates, error cases should be analyzed first: whether the failure was in peak processing, an incorrect adduct judgment, a missing database entry, or unreasonable candidate ranking. Only by locating the problem can you decide whether to improve the algorithm, supplement the reference data, or add experimental information.

    The real value of involving large language models in mass spectrometry analysis is to organize scattered computation, retrieval, and interpretation into a transparent workflow. Only by being evidence-centered, reproducibility-based, and constrained by explicit uncertainty expression can automated analysis move from “giving an answer” to “giving a trustworthy conclusion.”