The admin page's max tokens setting does nothing on the default model

A large control knob on its own panel, its cable unplugged and lying on the floor, beside a machine that keeps running.

Setting that does nothing Reported

A RAG sample on Azure OpenAI with two orchestrators, clean provider registries and a reasoning panel.

≈ 250,000 tokens per 1,000 calls, if a lower reasoning effort saves about 500 tokens per answer estimate

Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.

Repository
Azure-Samples/chat-with-your-data-solution-accelerator
Commit audited
f71c9c8
leanprompt version
0.1.0-dev.15
Audit date
Status
The maintainers have been told about this audit; no response yet.
Maintainers
the issue
How it ran
Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.

A RAG sample on Azure OpenAI with two orchestrators, clean provider registries and a reasoning panel. On the default reasoning deployment every answer runs at a fixed medium effort with no output limit, and the admin page's max tokens setting is not sent. The token figures are estimates from the code; the reasoning tokens saved are assumed.

leanprompt read the code at commit f71c9c8 and found 5 places where its LLM calls could use fewer tokens, plus 3 other problems, not scored. Static score: 80 of 100 (an estimate from the findings). The code may have changed since.

Findings

  1. LP-GE-03 Output and thinking budgets that fit the task

    src/backend/core/providers/llm/foundry_iq.py:491 · severity high · saves generation · size is assumed

    What happens. On the default deployment (gpt-5.4-mini, PostgreSQL, LangGraph) every answer is sent through the Responses API with reasoning effort fixed at medium and no output limit. The model's own default is none, and the admin page's max tokens and temperature are not sent on this path.

    The change. Read the effort from settings (for example AZURE_OPENAI_REASONING_EFFORT, default low or the current medium) and send max_output_tokens derived from the admin max tokens plus headroom for reasoning; treat a response.incomplete event as a cut-off answer.

    Why it helps. Reasoning tokens are billed as output. A grounded answer over five retrieved pages rarely needs medium effort, and with no limit a runaway answer is billed up to the model's 128,000-token output ceiling.

    Estimate about 250k output tokens per 1,000 calls (estimate), if low effort uses about 500 fewer reasoning tokens per answer than medium

    Assumptions. half of calls go through this path (postgresql is the azd default and maps to langgraph); about 800 reasoning tokens at medium and 300 at low per answer, not measured; about 350 visible answer tokens. Lowering effort can change answers; the reasoning panel (ADR 0007) still works at low.

    How big. usage.output_tokens_details.reasoning_tokens per answer on a fixed set of 30 to 50 questions, once at effort medium and once at low, plus the answer check on the same set

  2. LP-GE-03 Output and thinking budgets that fit the task

    src/backend/core/providers/orchestrators/agent_framework.py:290 · severity high · saves generation · size is assumed

    What happens. The Agent Framework orchestrator (the default for Cosmos DB deployments) sends the same fixed reasoning effort of medium and drops the admin max tokens whenever the answer model supports reasoning, so the answer has no output limit.

    The change. Use the same configurable effort and max_output_tokens as the LangGraph path, passed through ChatOptions.

    Why it helps. Same as the LangGraph path: reasoning tokens are output tokens, and medium on every answer is above what a grounded answer usually needs.

    Estimate about 250k output tokens per 1,000 calls (estimate)

    Assumptions. half of calls go through this orchestrator; same per-answer reasoning numbers as the LangGraph finding, not measured.

    How big. reasoning_tokens per answer from the Foundry agent run at effort medium and at low on the same question set

  3. LP-PC-02 Stable content first, without hurting meaning

    src/backend/core/providers/orchestrators/langgraph.py:186 · severity medium · saves prefill

    What happens. The LangGraph path puts the retrieved sources for the current question in a system message directly after the system prompt and before the conversation history, so the history changes position on every turn and the provider cannot reuse it from its cache.

    The change. Prepend the Sources block to the latest user message, the way agent_framework.py:236-245 already does for app-side retrieval, so the system prompt and earlier turns form a stable prefix.

    Why it helps. Azure OpenAI caches only an identical prefix of at least 1,024 tokens. With the sources in front, everything after the system prompt is recomputed at the full input price on every follow-up.

    Estimate about 146k prompt tokens per 1,000 calls not served from cache (estimate)

    Assumptions. langgraph serves half of calls; four-turn conversations; about 390 tokens per earlier exchange; with the fix turn k reuses the system prompt plus exchanges 1 to k-2. The system prompt is about 1,000 tokens (4,197 characters), close to the 1,024 minimum, so today it may not be cached at all. Moving sources next to the question can change answers.

  4. LP-PD-05 Drop stale history on purpose, not by stripping

    src/frontend/src/api/streamChat.tsx:233 · severity low · saves prefill · how often is assumed

    What happens. The frontend sends the whole thread on every turn and neither the request model (models/conversation.py:11) nor the orchestrators cap it, so long conversations resend every earlier answer.

    The change. Keep the last N exchanges (a setting, for example 10) in the orchestrator, dropping whole exchanges from the oldest end.

    Why it helps. Each earlier answer is resent as input on every later turn; past a point it adds cost and little to a grounded answer.

    Estimate about 84k prompt tokens per 1,000 calls (estimate), only from conversations longer than 10 exchanges

    Assumptions. 5% of calls come from conversations longer than 10 exchanges, carrying about 1,700 extra tokens each; not measured.

    How often. the distribution of message counts per /api/conversation request in App Insights

  5. LP-GE-03 Output and thinking budgets that fit the task

    infra/scripts/post-provision/post_provision.py:424 · severity low · saves generation · needs a fact to confirm

    What happens. Does the Foundry IQ knowledge base run an LLM query-planning step on every retrieval? The seed attaches the chat model and sets no retrievalReasoningEffort; the example response on Microsoft's page shows low as the stored value, which uses LLM planning.

    The change. Set retrievalReasoningEffort explicitly in the knowledge base body (minimal if planning does not improve retrieval for typical questions, low otherwise).

    Why it helps. Planning adds a model call per question on top of the answer call; minimal skips it.

    Estimate not estimated: depends on the stored effort

    Assumptions. Cosmos DB deployments only. The default is not stated in the docs read (https://learn.microsoft.com/en-us/azure/search/agentic-retrieval-how-to-create-knowledge-base, read 2026-11-27).

    To confirm. GET the cwyd-kb knowledge base and read retrievalReasoningEffort; check the retrieve activity array for a modelQueryPlanning entry and its token counts

Other problems the audit found

Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.

  1. The admin page's max tokens and temperature do nothing on the default model

    src/frontend/src/pages/admin/Configuration/Configuration.tsx:219 · LP-GE-17 Send the output cap the owner set, on every path · severity high · the same problem as finding 1

    What happens. The admin page offers 'OpenAI max tokens: Maximum number of tokens the chat model may generate per response.' With the default gpt-5.4-mini, complete() routes to reason() (foundry_iq.py:667-672) and agent_framework.py:274-292 builds ChatOptions without max_tokens or temperature, so both saved values are ignored and the answer has no output limit.

    The change. Map the admin max tokens to max_output_tokens on the reasoning path (with headroom for reasoning), or label the field as applying only to non-reasoning models.

    To check. Set max tokens to 200 in the admin page and ask a long question: the Responses request carries max_output_tokens and the answer is capped.

  2. A cut-off answer is stored and shown as complete

    src/backend/core/providers/llm/foundry_iq.py:364 · LP-GE-12 Read the finish reason before using an answer · severity medium

    What happens. chat() returns only choices[0].message.content and drops finish_reason, so on a non-reasoning model an answer that hits max_tokens (1,000 by default) is persisted as whole. reason() (foundry_iq.py:519-542) ignores the response.incomplete event in the same way.

    The change. When finish_reason is length or the stream ends with response.incomplete, log it and emit a reasoning or error event so the user and operator see that the answer was cut.

    To check. With max tokens at 50, the answer comes with a visible truncation notice and a log line.

  3. A second gpt-5-mini deployment for reasoning is provisioned but no code uses it

    infra/bicep/main.bicep:184

    What happens. The template deploys a second model (reasoningModelName gpt-5-mini, 50k TPM, main.bicep:184-186) and outputs AZURE_OPENAI_REASONING_DEPLOYMENT (main.bicep:822), and docs/QuotaCheck.md asks for 50k of quota for it, but nothing under src/ reads that variable; reasoning goes through the chat deployment (foundry_iq.py:667).

    The change. Either route reason() to the reasoning deployment, or drop the deployment and its quota requirement from the template and docs.

    To check. rg AZURE_OPENAI_REASONING_DEPLOYMENT src returns a reader, or the deployment is gone from main.bicep and QuotaCheck.md.

The maintainers’ response

No response from the maintainers yet.

How this was made

The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.

Corrections and takedown: email info@podwarden.com or open an issue.