What to Do When a Large Language Model API Underperforms After Integration
This article explains why LLM applications often underperform after API integration and how to fix it. It covers a four-layer attribution checklist, rewriting prompts into specifications, tuning randomness parameters, adding retrieval-augmented generation, building an evaluation loop, and handling cost and stability at the architecture level. The conclusion: model capability sets the ceiling, while the engineering chain determines actual results.
At 2 a.m., a friend of mine who works as an independent developer sent me a message with just three words: “I want to switch back to the previous-generation model.” I assumed he had been debugging until he broke. After half an hour of conversation, it turned out that what broke him was not the code but the output quality.
His application was already wired up to the model API. Calls went through, responses parsed correctly. But once it hit real business traffic, things went sideways: the same question asked twice produced two different answers; adding context made the model drift off-topic; accuracy on a simple classification task swung up and down; and one week after launch, user retention had not moved while API costs had tripled. Staring at his monitoring dashboard, he asked me: “Is the model bad, or am I bad?”
This is a highly representative problem. Many teams treat “the API is connected” as the finish line, when it is only the starting point. The quality of an LLM application is never determined by a single model. It is determined by a chain made up of model + prompt + context + parameters + post-processing + evaluation. When any link in that chain is weak, the symptom looks the same: “the model seems to have gotten dumber.”
1. First, Separate Model Capability Problems from Engineering Chain Problems
Before optimizing anything, you have to do attribution. Otherwise every effort is a guess. Work through the following order to localize the issue quickly.
Layer one: reproducibility check. Fix the input and the parameters, call the API several times in a row, and observe the variance in the output. If the variance is huge, the problem lies in sampling parameters and randomness control, not in the model’s comprehension.
Layer two: prompt sensitivity check. Change a single sentence in the prompt and see whether the output shifts dramatically. Extreme sensitivity means the prompt structure is unclear and the constraints are too weak.
Layer three: context length check. Gradually increase the number of conversation turns and the amount of concatenated content, and watch for the inflection point where quality decays. A lot of so-called “dumbness” actually happens after the context exceeds the model’s effective attention range.
Layer four: task difficulty check. Break the task into the smallest units. For example, split “generate a proposal” into “outline - fill in key points - polish,” and verify each stage. If each step performs well alone but the combination falls apart, the problem is in the orchestration.
The concise attribution snippet below is not about a specific calling convention; the point is to engineer “variable control”:
def diagnose(call_fn, prompt, params, n=5):outs = [call_fn(prompt, **params) for _ in range(n)]variance = len(set(outs)) / n # output dispersionreturn {"distinct_ratio": variance, "samples": outs}# Fix the input and parameters, check dispersion first, then talk about optimization
2. Prompts: Turn “Wishes” into “Specifications”
Most quality problems trace back to prompts that state a wish instead of a specification. “Write me a better piece of copy” is a wish. “You are an e-commerce editor; produce three short copies of no more than 40 characters each, every one containing a selling point and a call to action, avoiding absolute wording” is a specification. A specification has four elements: role, task, constraints, and output format.
Here is a stable four-section structure worth recommending:
[Role] You are a rigorous technical documentation editor.[Task] Turn the meeting notes below into a to-do list.[Constraints] Use only information from the source text; do not infer. When no owner is stated, write "TBD".[Output] A Markdown table with columns: Item | Owner | Due Date | Supporting Source Excerpt.
The “Supporting Source Excerpt” item is extremely important. It forces the model to produce traceable evidence and noticeably reduces fabrication. For structured output, always provide an example (few-shot prompting) and specify field types and enum ranges, so the model has a template to imitate instead of guessing.
3. Parameters and Randomness: Make Output Controllable
Temperature, nucleus sampling, maximum output length, and frequency and presence penalties are the main knobs for controlling style and stability. The rule of thumb: for extractive, classification, or reproducibility-critical tasks, turn randomness down; for creative generation, turn it up moderately. At the same time, record key parameters together with the prompt version to form a traceable configuration list, so you avoid the “it worked yesterday and fails today” situation with nothing to check against.
{"model": "general-purpose LLM","temperature": 0.2,"top_p": 0.9,"max_tokens": 1024,"prompt_version": "v3.2"}
4. Context and Knowledge: Don’t Make the Model Answer from Memory
Most “wrong answers” in enterprise scenarios are fundamentally cases where the model does not know your private knowledge. The solution is retrieval augmentation: split documents into semantically complete chunks, build a vector index, retrieve the few chunks most relevant to the question, assemble them into the prompt, and instruct the model to “answer only from the provided material, and state clearly when the material is insufficient.”
Four things matter in engineering: chunking granularity (split by semantic段落 rather than fixed character counts), number of retrieved chunks (too many dilute attention), reranking (coarse recall first, then fine ranking), and citation labeling (attach source excerpts to the answer for verification). This combination usually pays off far more than swapping models.
5. Evaluation Loop: No Measurement, No Optimization
You must build a small but fixed evaluation set covering typical phrasings, boundary phrasings, malicious inputs, and empty inputs. Every time you change a prompt or a parameter, run a regression pass and record accuracy, format compliance rate, average latency, and cost per call. A sketch of the structure:
cases = [{"q": "...", "expect": "..."}]def evaluate(call_fn, cases):ok = 0for c in cases:out = call_fn(c["q"])ok += int(c["expect"] in out)return ok / len(cases)
With a baseline in place, team discussion shifts from “I feel” to “the data says,” and iteration speed improves markedly.
6. Cost and Stability: Architecture-Level Safeguards
Once call volume grows, you need to cache high-frequency repeated requests, summarize long text before putting it into the prompt, split large tasks into small ones and run them in parallel, and set timeouts, retries, and fallback strategies. Observability is just as essential: a logging service records request and response summaries, and monitoring alerts watch failure rate and latency percentiles. If elasticity and data persistence are involved, you can run stateless services on a container platform and store evaluation sets and intermediate artifacts in object storage to scale with demand.
7. Closing Thoughts
My friend did not switch models in the end. He did three things: rewrote the prompt into the four-section specification, lowered randomness and pinned the version, and added retrieval augmentation plus thirty evaluation cases. A week later, task success rate went from erratic to stable, and cost actually went down.
The conclusion is plain: model capability is only the ceiling; the engineering chain determines how much of it you actually get. Do attribution, prompts, parameters, retrieval, evaluation, and cost properly, and most “it doesn’t work well” turns into “actually pretty good.” To further lower the barrier of building this yourself, you can also draw on general capabilities such as model services, log monitoring, and containerized deployment from Baidu AI Cloud, and keep your focus on the business and the data themselves.
