Why LLM APIs Behave Differently from Web Chat: Optimizing Extraction Tasks in Practice

    This article explains why LLM API responses often feel stiffer and less accurate than web chat responses, even though the API does not run a weaker model. It covers the system prompts, orchestration, and sampling differences behind the gap. It then shows how to write structured prompts and run controlled evaluations for relation extraction.

    When developers build AI applications, they often find that a model feels stiff or less natural when called through the API, and that it may perform worse than the same model in a web chat window. This gap is most noticeable in strict extraction tasks, where the API output often falls short. The cause is not a weaker model behind the API. It comes from differences in product design and engineering logic. This article examines those causes from a technical standpoint and describes an engineering approach for tasks such as relation extraction.

    1. Core Differences Between Web Chat and the API: Product Orchestration vs. Raw Calls

    When a user enters a sentence in a web chat window and gets a satisfactory answer, the system does much more than run model inference. The result comes from a base model, a harness (an orchestration framework), and agent rules working together.

    1. Implicit system prompts and context management
      Web chat products usually add many system instructions behind the user’s input to create a smooth, safe, and intuitive experience. These instructions include role settings, conversation style constraints, safety filtering rules, and conversation history. When a developer calls the API directly, the request usually contains only the raw user prompt. The model lacks background and constraints, so it often behaves like a blank slate and gives unfocused answers.

    2. Tool calling and multimodal orchestration
      Modern web chat applications are usually complex agent systems. They decide based on user intent when to enable deep thinking mode, when to call web search, and when to parse uploaded files. These product-layer capabilities create the impression that the model knows a great deal. A standard API call executes a single request by default, so the caller must supply every piece of background and every constraint.

    3. Randomness in generation
      During generation, the model uses sampling parameters such as temperature and top-p. Even with the same prompt, repeated requests may return different answers, a behavior often called “drawing cards.” Web chat products are usually tuned extensively at the product layer to balance randomness and stability. An API call that does not set these parameters correctly may show more variation in quality.

    2. Task Mismatch: From Free Conversation to Strict Extraction

    In concrete business scenarios, such as sentence-level relation extraction, developers who keep using the chat-style prompts from the web interface often get much weaker results.

    Conversation works by adding context and allowing free interpretation. The model can elaborate and speculate, and it may add reasonable subjective inferences. Information extraction requires restraint. The model must not add relations that the text does not state, must not reverse the subject and object of a relation, and must not add fields outside the schema. If a developer simply tells the model to “understand this passage and extract relations,” the model may treat extraction as free interpretation. This leads to hallucinations or format errors.

    3. Advanced Practice: Building Structured Extraction Prompts

    For strict tasks, the API needs structured prompt engineering that supplies the constraints the product layer would otherwise provide. For relation extraction, split the prompt into the following five core parts.

    1. Entity type and relation allowlist
      Define the task space clearly. Tell the model to identify only the entity types (such as “Person,” “Organization,” and “Location”) and relation categories (such as “born_in” and “works_for”) provided in the prompt. Forbid the model from creating new categories.

    2. Direction and decision criteria for each relation
      For relation extraction, the direction between subject and object matters. For example, the “born_in” relation must have a Person as the subject and a Location as the object. Give a clear criterion for each relation.

    3. Return null when uncertain, and strictly forbid guessing
      This rule is key to reducing hallucinations. The prompt should state: “If the relation is not explicitly mentioned in the text, output null for the corresponding field. Never infer it from common knowledge.”

    4. Attach source text evidence to each relation
      Require the model to return the source text snippet that supports each relation. This makes manual review easier. It also forces the model to check the original text before it generates a relation, which lowers the chance of hallucination.

    5. Fixed JSON schema and few-shot boundary examples
      Require the model to follow a specific JSON structure. Provide two or three examples that cover boundary cases, such as no relation and multiple relations. In-context learning from these examples helps stabilize the output format.

    The following is a standard JSON schema prompt constraint example:

    1. {
    2. "task": "relation_extraction",
    3. "allowed_entities": ["Person", "Organization", "Location"],
    4. "allowed_relations": [
    5. {
    6. "relation": "works_for",
    7. "subject_type": "Person",
    8. "object_type": "Organization",
    9. "definition": "The person is currently or was previously employed by the organization."
    10. }
    11. ],
    12. "output_format": {
    13. "type": "array",
    14. "items": {
    15. "subject": "string (Entity name)",
    16. "subject_type": "string",
    17. "relation": "string",
    18. "object": "string (Entity name)",
    19. "object_type": "string",
    20. "evidence": "string (Original text snippet)"
    21. }
    22. },
    23. "rules": [
    24. "1. Only use relations from the allowed_relations list.",
    25. "2. If a relation is not explicitly stated, return an empty array.",
    26. "3. Do not infer or guess relationships based on world knowledge."
    27. ]
    28. }

    4. Scientific Evaluation: Measuring Results with Controlled Variables

    Many developers compare one web chat result with one API output and conclude that “the API is weaker.” This method is not scientific. A valid evaluation must strictly control variables:

    • Same model version: Make sure the web version and the API call use exactly the same underlying model weights.
    • Same thinking mode: Turn the same reasoning enhancement mode on or off for both.
    • Same test set: Use a standardized evaluation dataset instead of random questions.
    • Repeated calls: Because generation is random, call the API several times with the same input and compute average metrics.
    • Objective metrics: For relation extraction, calculate precision, recall, and F1 score to quantify the difference.

    As LLM engineering develops, mainstream cloud providers keep updating their APIs. General-purpose LLM APIs now increasingly support advanced capabilities such as web search, deep thinking, file input, and link reading. Some of the product orchestration that web chat provides can therefore be configured on the server side through API parameters.

    These capabilities are usually disabled by default. Calling an API used to mean buying pure model inference compute. Now, developers also need to decide how much product-layer orchestration to add.

    When an API seems “dumb,” the cause is often not poor prompt writing. Developers have left to the model all the work that web chat does silently. When building complex applications, developers can consider platforms such as Baidu AI Cloud, which offer LLM services and orchestration tools. Prompt management, context memory, and tool calling can be packaged as standardized engineering modules. These modules can reproduce or even exceed the web chat experience on the API side. With disciplined engineering, LLM APIs can become stable and efficient tools for enterprise productivity.