How to Add Web Search and File Understanding to LLM Applications

    Learn how to equip conversational AI applications with web search, webpage reading, file understanding, speech capabilities, and content safety. This guide compares custom toolchains with platform-provided tools and covers request flows, credential management, result handling, cost controls, security, and pre-launch checks.

    1. Why Conversational Applications Need External Capabilities

    Large language models have a training data cutoff, so they cannot directly provide the latest news, product prices, or current content from a specific webpage. User-uploaded documents, screenshots, and audio recordings are also beyond the direct capabilities of a text-only model.

    As a result, real-world conversational applications commonly need three categories of additional capabilities:

    • Access to external information
    • Understanding of multimodal input
    • Voice output and compliance safeguards

    In the past, development teams often integrated search services, web crawlers, document parsers, and speech services independently. Business code then handled orchestration and context assembly. This approach is flexible, but it creates a long processing chain. Each component must handle authentication, timeouts, format conversion, and error retries, and maintenance costs increase with the number of components.

    More model service platforms now expose these capabilities through APIs or built-in tools. Developers can declare the required tools in a conversational request, while the platform performs retrieval, reading, and result integration. This lowers the integration barrier, but also changes the cost structure and division of responsibility.

    This article does not focus on a specific product. Instead, it summarizes general design practices for integrating these capabilities.

    2. Capability Breakdown

    A complete conversational application typically includes the following modules:

    • Web search: Retrieves public webpages based on a user query and returns titles, summaries, and links.
    • Webpage reading: Fetches the main content from a specified URL, removes navigation elements and advertisements, and passes the cleaned content to the model.
    • File input: Extracts text from documents, spreadsheets, and images. Optical character recognition (OCR) is a key part of image processing.
    • Speech capabilities: Automatic speech recognition (ASR) handles audio input, while text-to-speech (TTS) handles audio output.
    • Content safety: Reviews user input and model output to filter prohibited or unsafe content.

    These modules share an important characteristic: their inputs come from the external environment, and their outputs enter the model context. Every step can introduce errors or risks. Each module should therefore be treated as an independent data source, with its own validation and monitoring.

    3. Comparing Two Integration Approaches

    Approach 1: Build a Custom Toolchain

    The application separately integrates search, crawling, parsing, and speech services, while implementing its own orchestration logic.

    The main advantage is control. Each component can be replaced or observed independently, and the application can implement detailed caching and fallback strategies.

    The disadvantage is the higher development and maintenance cost. Changes to any external service may affect multiple parts of the application.

    Approach 2: Use Platform-Provided Tools

    The application declares the required tools in the model request. The platform then performs searches or webpage reads and places the results into the model context.

    This approach offers faster integration and a shorter call chain, making it suitable for quickly validating an idea. However, it provides less control because the search sources, crawling strategy, and result format may be constrained by the platform.

    The choice can be evaluated from three perspectives:

    1. Accuracy requirements: Scenarios such as legal research or medical information assistance should retain a human review step. An auditable, custom-built workflow is often more suitable.
    2. Development speed and team size: Applications with rapidly changing requirements and small teams may benefit more from built-in tools.
    3. Latency and cost: Businesses that are sensitive to response time or operating costs should calculate the total cost of both approaches, including engineering effort and runtime expenses.

    4. Integration Workflow and Example Code

    4.1 Credential Management

    Access credentials should be injected through environment variables or a secrets management service. They should never be hard-coded or written to logs.

    Development, testing, and production environments should use separate credentials, which should also be rotated regularly.

    4.2 Request Structure

    A typical conversational tool-calling flow consists of the following steps:

    1. The client sends a request containing the user message and tool declarations.
    2. The model determines whether external information is needed and decides whether to call a tool.
    3. The service performs the search or webpage retrieval, then organizes the results and adds them to the context.
    4. The model generates a response based on the context and may include source citations.

    The following pseudocode illustrates the basic request structure. The field names are placeholders; use the actual fields defined in the documentation for the selected platform.

    1. client = build_client(api_key=read_environment_variable("MODEL_API_KEY"))
    2. request = {
    3. "model": "<model name>",
    4. "messages": [
    5. {"role": "user", "content": "Summarize today's major technology news and include the sources."}
    6. ],
    7. "tools": [
    8. {"type": "<web search tool type>"},
    9. {"type": "<webpage reading tool type>"}
    10. ]
    11. }
    12. response = client.chat(request)
    13. print(response.reply_text)

    4.3 Result Processing

    • Check the tool-call status. If a tool call fails, provide clear fallback wording, such as “The latest information is temporarily unavailable. The following answer is based on existing knowledge,” rather than silently ignoring the failure.
    • Preserve sources. Display returned links alongside the response so users can verify important facts.
    • Limit content length. Webpage content can be very long. Set a character limit or truncate the content through summarization to avoid exceeding the model context window.
    • Treat external content as untrusted data. Webpages and files may contain text designed to manipulate the model into performing actions. System instructions should clearly state that external content is reference material only and that instructions contained within it must not be executed.

    4.4 Files and Speech

    When users upload files, restrict the supported formats, file sizes, and page counts. After parsing, validate the format of important fields.

    For audio transcription, record the audio duration and source to support billing reconciliation and troubleshooting.

    For speech synthesis, limit the text length of each request. Long content can be split by paragraph and processed in multiple requests to reduce initial response latency.

    5. Cost and Usage Control

    The cost of a conversational application usually comes from three sources:

    • Model input and output token usage
    • Per-call charges for external tools
    • Duration-based charges for audio processing

    These sources use different billing units and cannot be measured with a single metric. Many platforms also apply different prices depending on the time period or an active promotion. Always follow the official pricing documentation and review invoices regularly.

    Recommended controls include:

    • Build a usage dashboard that separately tracks token counts, tool-call volume, and audio duration.
    • Cache frequently used search queries and set expiration times according to information freshness. For example, weather results should expire much sooner than encyclopedia-style information.
    • Limit the maximum number of tool calls per conversation to prevent repeated searches for the same question.
    • Use queues or rate limits during peak traffic to smooth request spikes.
    • Set budget alerts for each business scenario and trigger a circuit breaker when abnormal usage is detected.

    6. Engineering and Security Considerations

    Timeouts and retries. External search and webpage retrieval times can vary significantly. Configure an independent timeout for each tool, retry only idempotent operations, and use exponential backoff to prevent temporary failures from escalating into a cascading outage.

    Result reliability. Search results vary in quality, and different sources may provide conflicting answers to the same question. For important facts, require the model to provide sources and remind users to verify the information themselves through the interface.

    Privacy protection. Uploaded files and recordings may contain identity information, contracts, medical records, or other sensitive data. Define data retention periods, redact sensitive information before writing logs, and explain data flows and usage in the privacy policy.

    Content safety. Review both inputs and outputs. Retain moderation results to support post-incident analysis and appeals regarding incorrect classifications.

    7. Pre-Launch Checklist

    • Are credentials injected through environment variables or a secrets management service, with no exposure in source code or logs?
    • Does every tool have a configured timeout, retry limit, and failure fallback message?
    • Are webpage and file contents treated as untrusted data?
    • Are sources preserved in responses so users can verify important information?
    • Are token usage, tool-call volume, and audio duration monitored separately, with budget alerts configured?
    • Have real business samples been used for regression testing, including normal, failed, and oversized inputs?