Why LLM API Results Differ from Chat Interfaces: Understanding the Orchestration Layer

    LLM APIs often seem to perform worse than chat interfaces even when using the same model. This article explains that the difference comes from the hidden orchestration layer—system prompts, conversation history, retrieval, and tool calls—not the model itself. It walks through building production-grade prompts for relation extraction, validating structured outputs in code, and running controlled evaluations so you can measure API performance fairly.

    Why the Same Model Feels Different Through an API

    Many developers have run into this: ask a question in a chat interface and the answer is well-organized and contextually complete; send the same sentence through the API and the output suffers from missing entities, wrong extractions, or messy fields. The easy conclusion is that the API is “less intelligent,” or that your prompt is badly written.

    Neither conclusion is accurate. To diagnose the problem, you first need to understand what goes into a single “answer.”

    A Chat Interface Is More Than One Model Call

    A user-facing chat product is typically a full processing pipeline, not a bare model call. Common components include:

    • System instructions: role definitions, tone requirements, safety rules, and output format constraints pre-written by the product team.
    • Conversation history: previous turns, sometimes compressed or summarized before being appended.
    • File parsing results: uploaded documents converted to text and injected as context.
    • Retrieved material: passages recalled from search or a knowledge base, provided alongside the question.
    • Tool call decisions: the system decides whether to search the web, run calculations, or invoke other functions, then feeds tool results back into the context.
    • Thinking mode switching: whether multi-step reasoning is enabled may also be decided at the product layer.

    All of this is invisible to the user, who only sees the final paragraph of text. What looks like “model performance” is actually the combined result of the model plus orchestration logic.

    The product layer adds extra constraints, too. For example, system instructions may require the model to avoid overconfident claims, proactively add background, or adopt a specific tone—rules that reshape both output style and the model’s judgment about what to say.

    What an API Does by Default: Execute Only Your Request

    When you call an API, the server generally processes only what’s in the request body. It won’t add history for you, and it won’t automatically retrieve documents, parse files, or enable tools. Any context or constraints not in the request are unknown to the model.

    This means the caller is responsible for:

    1. Managing context: deciding which history to keep and how to truncate or compress it.
    2. Injecting material: if reference documents are needed, you must parse, split, and place them into the request yourself.
    3. Declaring constraints: output format, allowed fields, and handling of uncertainty should all be written out explicitly.
    4. Orchestrating tools: if external capabilities are needed, you define tool descriptions, execute them when the model requests a call, and return the results to the model.

    Another often-overlooked factor is randomness. Generation involves sampling, so the same prompt can yield slightly different results across calls. Parameters like sampling temperature and max output tokens also affect stability. Drawing conclusions from a single call makes it easy to mistake chance for a pattern.

    So the experience of “asking directly works better” is real—but it doesn’t prove the product’s underlying model is stronger. It mostly shows that the product layer has done a lot of work on the user’s behalf.

    Why Relation Extraction Requires Restraint

    Chat and information extraction place opposite demands on a model.

    In chat, the model can fill in context, infer implications, and help the user understand a passage—valuable abilities for Q&A.

    In relation extraction, the model must strictly stay faithful to the source text. Its job is to identify explicitly stated relations, not to interpret or extend the text. Common failure modes include:

    • Inventing unstated relations: the text only mentions two entities appearing together, but the model infers an “employment” or “affiliation” relation.
    • Reversing direction: the text says “A founded B,” but the output reads “B founded A.”
    • Adding fields outside the schema: the model adds confidence scores, explanations, timestamps, and so on, breaking downstream parsing.

    If your prompt still uses a conversational tone—say, “please analyze the relationships between people in this passage”—the model will lean toward open-ended interpretation. To get stable structured output, the prompt must be rewritten as a specification.

    Structuring the Prompt in Five Parts

    A workable relation extraction prompt should contain the following five components.

    1. Entity types and a relation whitelist

    Spell out the allowed entity types and relation names; never output relations outside the whitelist.

    1. Entity types: PERSON, ORGANIZATION, LOCATION
    2. Relation whitelist: founded_by, located_in, works_for

    2. Direction and criteria for each relation

    For each relation, define the head and tail entity types, the direction, and the判定 criteria.

    1. founded_by: head is ORGANIZATION, tail is PERSON.
    2. Criterion: the text explicitly states that this person founded this organization.
    3. located_in: head is ORGANIZATION or PERSON, tail is LOCATION.
    4. Criterion: the text explicitly states that the subject is located in or headquartered at this place.
    5. works_for: head is PERSON, tail is ORGANIZATION.
    6. Criterion: the text explicitly states that this person works at or holds a position in this organization.

    3. Output empty values when uncertain—no guessing

    This rule is key to suppressing hallucinations. State it directly: relations not explicitly expressed in the text are not output; when entity references are ambiguous, do not fill them in using common sense.

    4. Attach source evidence to every relation

    Require the model to put the supporting text snippet in an evidence field. Evidence makes manual spot checks easy and anchors the model to the source text during generation.

    5. Fix the JSON schema and provide edge-case samples

    The output structure should be fixed, with two or three edge-case examples: entities sharing a name, sentences where relation direction is easily confused, and sentences where entities co-occur without any relation.

    Here’s an example output structure:

    1. {
    2. "relations": [
    3. {
    4. "head": "a tech company",
    5. "relation": "founded_by",
    6. "tail": "Zhang San",
    7. "evidence": "The company was founded by Zhang San in 2010."
    8. }
    9. ]
    10. }

    Specify that when there are no results, the model outputs {"relations": []} rather than omitting the field or returning a natural-language explanation.

    Calling the API and Validating Outputs

    Beyond the prompt, the calling side also needs validation. The example below illustrates the approach; the client object is a placeholder—replace it with your actual SDK call.

    1. import json
    2. ALLOWED_RELATIONS = {"founded_by", "located_in", "works_for"}
    3. REQUIRED_KEYS = {"head", "relation", "tail", "evidence"}
    4. def build_messages(sentence: str, schema_prompt: str) -> list[dict]:
    5. return [
    6. {"role": "system", "content": schema_prompt},
    7. {"role": "user", "content": f"Source text: {sentence}"},
    8. ]
    9. def validate(payload: dict, sentence: str) -> list[dict]:
    10. relations = payload.get("relations")
    11. if not isinstance(relations, list):
    12. raise ValueError("relations field missing or wrong type")
    13. clean = []
    14. for item in relations:
    15. if set(item.keys()) != REQUIRED_KEYS:
    16. continue # discard results with extra fields
    17. if item["relation"] not in ALLOWED_RELATIONS:
    18. continue # discard relations outside the whitelist
    19. if item["evidence"] not in sentence:
    20. continue # evidence must be a substring of the source text
    21. clean.append(item)
    22. return clean
    23. def extract(client, sentence: str, schema_prompt: str) -> list[dict]:
    24. # client is a placeholder; replace with your actual SDK call
    25. raw = client.chat(build_messages(sentence, schema_prompt))
    26. payload = json.loads(raw)
    27. return validate(payload, sentence)

    This code reflects two principles. First, outputs pass structural validation before reaching downstream systems. Second, the evidence field must be findable in the source text; otherwise it’s treated as model-invented content.

    Evaluate with Controlled Variables

    To determine whether the API really underperforms the chat interface, you need a proper evaluation method. Comparing one web chat answer against one API output proves nothing, because their contexts, parameters, and output protocols differ.

    Your evaluation should control for:

    • The same model;
    • The same thinking mode and sampling parameters;
    • The same batch of sentences, including positive and edge cases;
    • The same output protocol and parsing rules;
    • Multiple repeated calls, with statistical aggregation.

    Common metrics are Precision, Recall, and F1, computed per triple (head, relation, tail):

    1. def score(pred: set, gold: set) -> dict:
    2. tp = len(pred & gold)
    3. precision = tp / len(pred) if pred else 0.0
    4. recall = tp / len(gold) if gold else 0.0
    5. f1 = 2 * precision * recall / (precision + recall) if precision + recall else 0.0
    6. return {"precision": precision, "recall": recall, "f1": f1}

    Repeat calls on the same batch of samples, record the scores each time, then compute the mean and variance. If variance is high, use majority voting across runs or reduce sampling randomness. Only after these conditions are unified is it meaningful to compare different approaches.

    Making the Invisible Work Explicit

    Back to the original question. When an API seems “less intelligent,” it’s often because work previously handled by the product layer now falls entirely on the caller. The shift can be summarized this way: you used to buy mainly a model call; now you also need to decide how much product-layer orchestration to buy or build yourself.

    Developers can audit their systems in this order:

    1. List product-layer capabilities: history management, file parsing, retrieval augmentation, tool calling, output validation—confirm item by item which ones you need to implement yourself.
    2. Make system instructions explicit: turn implicit rules into reviewable text, covering tone, boundaries, refusal conditions, and output format.
    3. Fix the output protocol: use structured output with validation and fallbacks on the calling side.
    4. Build an evaluation set: collect positive, negative, and edge-case samples, and re-measure metrics after every change.
    5. Log parameters and versions: ensure experiments are reproducible so parameter changes aren’t misread as performance changes.

    Following this order, most “poor performance” problems can be traced to a clear cause—and fixed with a specific change.