Building an Automated LLM-Driven Workflow for Historical Document Collection

    This article presents a practical workflow for automating historical document collection with large language models (LLMs). It explains why LLMs help with intent parsing and entity expansion, while introducing risks such as fabricated facts, defensive refusals, and format drift. The core approach is a five-layer pipeline—intent, retrieval, acquisition, conversion, and validation—paired with evidence-first constraints, forced citations, cross-verification, and schema checks. The article also covers how to turn policy stops into observable states, improve ingestion and reading experiences, and close the tuning loop with metrics like recall, evidence coverage, and retry rates. It is intended for developers building controllable, long-term document collection systems.

    1. Background: Why Put LLMs in a Historical Document Workflow

    In personal knowledge management, the most time-consuming step is often not reading, but “finding everything, obtaining complete copies, and putting them in the right place.” A typical historical document collection chain includes requirement breakdown, retrieval, download, local synchronization, format conversion, and ingestion for display. The traditional approach relies on people repeatedly switching between multiple search entry points, which produces unstable recall and is hard to reuse.

    After introducing LLMs, natural-language requirements can be translated directly into retrieval intent, and the ability to generate divergent associations is significantly better than keyword enumeration. However, this also brings three new problems:

    • Factual content may be “completed” into plausible but incorrect information.
    • The model may be overly conservative about content that could involve copyright or source compliance, terminating the process midway.
    • Output formats drift over long chains, causing downstream conversion failures.

    Therefore, the engineering focus is not on “which model to choose,” but on how to converge the model’s uncertainty within verifiable boundaries.

    2. Capability Breakdown: Differences in Divergence, Convergence, and Compliance Tendencies

    Different models show different capability profiles on the same task, which can be evaluated across three dimensions.

    • Divergence and recall breadth: Models with broad world knowledge are more likely to provide clues across languages and eras, making them suitable for generating candidate search terms and expanding entities such as related people, institutions, era names, and place names.
    • Factual consistency: For steps that require external evidence, the model should only “propose hypotheses” and should not directly output conclusive facts.
    • Compliance and defensive tendencies: Some models proactively stop when they encounter potentially restricted content. This is an advantage in general question answering, but in a batch collection pipeline it can cause silent task failures.

    The conclusion is: delegate divergence to the model, delegate judgment to rules and evidence, and turn termination into an observable status code.

    3. Reference Architecture: A Five-Layer Pipeline

    1. Intent layer: Parse requirements and output a structured task object.
    2. Retrieval layer: Perform multi-path recall and deduplication to generate a candidate list.
    3. Acquisition layer: Perform controlled downloads and local synchronization, writing to object storage or a local directory.
    4. Conversion layer: Parse, clean, and unify content into a readable format.
    5. Validation layer: Verify evidence, score quality, retry failures, and trigger alerts.

    A sample task structure is shown below:

    1. {
    2. "task_id": "hist-2024-0007",
    3. "query": "Water conservancy records in local gazetteers from a certain period",
    4. "entities": ["place name", "era name", "institution"],
    5. "constraints": {
    6. "max_results": 50,
    7. "allowed_domains": [],
    8. "require_evidence": true
    9. },
    10. "on_policy_stop": "record_and_continue"
    11. }

    The key design points are require_evidence and on_policy_stop: the former forces any factual output to include a traceable source, and the latter turns “the model is unwilling to continue” from an exception into a normal state that can be recorded, skipped, and compensated.

    4. Suppressing Hallucination: Evidence-First Constraints

    • Two-stage generation: The first stage only produces search queries and entity expansions, without factual statements; the second stage only summarizes and categorizes the fetched text.
    • Forced citation: Each conclusion is bound to a source identifier and fragment location; items without citations are discarded.
    • Cross-verification: The same fact must be supported by two or more independent sources before entering the official library; otherwise, it is marked as pending verification.
    • Structured output validation: Use a fixed schema to constrain the return format; retry if the schema does not match.
    1. def accept(item):
    2. if not item.evidence or len(item.evidence) < 2:
    3. return "pending"
    4. if not schema_valid(item):
    5. return "retry"
    6. return "accepted"

    5. Handling “Stopping Midway”: Engineering Defensive Refusals

    When the model proactively terminates, the recommended approach is to set a policy callback and a fallback path: record the stop reason and the current step, switch to a backup retrieval channel, narrow the request scope and retry, and if it still fails, move the task to a manual queue. At the same time, use prompts to clarify that the task is retrieval and format organization of public historical materials, reducing unnecessary ambiguity.

    For monitoring, it is recommended to build dashboards for “task completion rate,” “average retry count,” and “pending verification ratio,” and connect them to logging services and alerts to avoid silent failures accumulating over time.

    6. Ingestion and Reading Experience

    The conversion layer unifies heterogeneous content into plain text and structured metadata, removing watermarks and navigation noise while preserving section hierarchy. For storage, a hybrid approach of local directories plus object storage can be used, with metadata maintained in a lightweight database and the reading page limited to rendering and search. Incremental synchronization uses content fingerprints for deduplication, ensuring repeated runs do not produce duplicate entries.

    7. Evaluation and Tuning Loop

    Evaluation metrics should cover recall rate, evidence coverage rate, first-pass format rate, time per task, and manual intervention rate. The tuning order is to first fix rules and schema constraints, then adjust prompt strategies, and only then consider switching models. If elastic compute is needed to handle batch parsing and conversion, scalable batch jobs can be built on general capabilities such as the container platform, object storage, and monitoring and alerting offered by Baidu AI Cloud.

    8. Conclusion

    The value of automation comes from controllability, not from stronger single-shot generation. Only by using divergent capabilities to expand clues, rules and evidence to converge conclusions, and refusals and failures as part of an observable process can we build a historical document collection and reading system that remains usable over the long term.