Building Custom LLM Applications: A Practical Guide to Tool-Based Architecture

    This article explains how LLM application development is shifting from single API calls to assembling modular tool capabilities. It breaks down five common tool categories—web search with citations, deep reasoning search, multi-format file input, link reading, and input/output safety checks—and covers cost governance, a recommended four-layer architecture, and common pitfalls with an acceptance checklist. Developers will find practical guidance for shipping custom LLM applications that are safe, verifiable, and cost-predictable.

    1. From Calling a Model to Assembling Capabilities

    For a while, building LLM applications mostly meant prompt engineering and single API calls. As these applications moved from Q&A toys to real business use cases, a single model’s inference could no longer cover the full set of requirements. Users attach contracts, reports, and scanned documents. They paste a URL and ask for a summary. They ask follow-up questions that require the latest information. They also slip prohibited content into the conversation.

    As a result, the engineering focus shifted from calling a model to assembling capabilities—mounting atomic capabilities such as retrieval, parsing, crawling, and risk control onto the model side as tools, and letting the model decide on its own when to invoke them during inference.

    This paradigm delivers two direct benefits. The first is controllability: each type of capability has an independent switch and independent metering, so cost and risk can be governed separately. The second is reusability: the same tool orchestration logic can support customer service, legal review, research report summarization, tutoring, and many other scenarios. What developers actually need to build by hand is only the business shell and the interaction experience.

    2. A Technical Breakdown of Five Common Tool-Based Capabilities

    2.1 Web Search with Citation Traceability

    Web search addresses the timeliness of model knowledge and fact verification. In engineering terms, it typically involves five stages: query rewriting, retrieval and recall, result reranking, content extraction, and citation backfilling. The key design point is verifiable citations: every factual conclusion in an answer should map back to a specific source snippet, and the frontend should present it as a superscript marker or a source card so users can judge credibility. You also need a retrieval trigger policy to avoid pointless retrieval for pure computation or pure rewriting questions, which wastes latency and cost.

    When a question requires multi-hop reasoning, a single retrieval is often insufficient. Deep reasoning search lets the model repeatedly issue retrievals within a multi-step reasoning chain, read candidate links, and revise the next query based on new evidence, forming a loop of reason, retrieve, and reason again. For implementation, it is advisable to cap the maximum number of iterations and the total latency budget, and to cache intermediate evidence in a structured way to prevent the same snippet from being fetched repeatedly. This capability suits tasks that require cross-validation, such as competitor analysis, regulatory comparison, and root-cause troubleshooting.

    2.3 Multi-Format File Input

    Materials in real business scenarios come in complex formats, commonly including documents, spreadsheets, presentations, and images. The processing pipeline is generally divided into format detection, layout analysis, text extraction, table structuring, and reconstruction of mixed text and images. For scanned files and images, you need to bring in optical character recognition (OCR). For tables, you should preserve row and column semantics rather than flattening them into plain text; otherwise, numerical Q&A will degrade noticeably. It is recommended that extraction results carry page numbers and position information to support an experience where the answer points to a specific page in the original document.

    When a user pastes a URL directly, the ideal behavior is to automatically detect it, crawl it, extract the main content, and then answer in context. The difficulties concentrate on dynamically rendered pages, login walls, anti-crawling mechanisms, and noise cleanup. In engineering terms, you should perform main-content density analysis to strip navigation and ads, and provide an explicit fallback notice when crawling fails, rather than letting the model guess the content out of thin air.

    2.5 Input and Output Safety Checks

    Applications that serve the public must place a checkpoint before and after the model: on the input side, detect prompt injection and sensitive information; on the output side, intercept prohibited content, privacy leaks, and unauthorized commitments, returning a structured refusal identifier rather than free text when a risk is hit. It is worth emphasizing that tool-based risk control is only a baseline capability. Service providers still need to fulfill compliance obligations such as content moderation, algorithm and model registration, and generated-content labeling. This responsibility cannot be transferred by flipping a single parameter switch.

    3. Billing Model and Cost Governance

    The cost structure of tool-based capabilities has two parts: input and output unit metering on the model side, and metering by call count or processing volume on the tool side. Heavy-processing tasks such as file parsing and web crawling are usually the main cost drivers. Governance measures include: setting a per-session call limit for each type of tool; slicing long documents for relevance before sending them to the model; building result caches for high-frequency identical queries; and splitting usage dashboards by business dimension within the monitoring and alerting system to locate the source of abnormal calls.

    1. # Skeleton: tool orchestration with budget and audit
    2. budget = {"search": 5, "read_url": 3, "parse": 2}
    3. usage = {k: 0 for k in budget}
    4. def call_tool(name, payload, user_id):
    5. if usage[name] >= budget[name]:
    6. return {"status": "skipped", "reason": "budget_exceeded"}
    7. usage[name] += 1
    8. result = TOOL_REGISTRY[name](payload)
    9. audit_log(user_id, name, payload, result) # full-chain traceability
    10. return result

    A four-layer structure is recommended. The access layer handles authentication, rate limiting, and multi-device adaptation. The orchestration layer handles tool registration, invocation policies, and budget control. The capability layer connects to common cloud service categories such as retrieval, parsing, crawling, and risk control—for example, object storage for retaining original files, a message queue for asynchronous parsing tasks, and logging and monitoring/alerting services for usage and quality observation. The data layer accumulates sessions, evidence snippets, and user feedback to form a traceable evaluation set. Asynchronization is especially important: large-file parsing should go through a task queue with callbacks to avoid long-connection timeouts.

    5. Common Pitfalls and an Acceptance Checklist

    First, evidence disconnected from answers—enforce citation backfilling. Second, long contexts stuffed with noise—slice first, then reason. Third, runaway iterative retrieval—set iteration and timeout limits. Fourth, missing compliance—put moderation and generated-content labeling in place up front. Fifth, lack of evaluation—build a regression dashboard covering factual accuracy, citation correctness, refusal accuracy, average latency, and cost per call, and run the baseline every time you adjust a tool policy. Following this path, individual developers and small teams can also deliver a custom LLM application with a low barrier to entry that is safe, verifiable, and cost-predictable.