The page leanprompt report --html writes for Azure-Samples/chat-with-your-data-solution-accelerator at commit f71c9c8, audited 2026-11-27. Every figure on this page is an estimate from reading the code, not a measurement of the app in use. Corrections and takedown: email info@podwarden.com or open an issue. Back to the audit of Azure-Samples/chat-with-your-data-solution-accelerator

leanprompt audit of Azure-Samples/chat-with-your-data-solution-accelerator

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.

4 places where this app pays for tokens it doesn't need

The biggest, at src/backend/core/providers/llm/foundry_iq.py:491, about 250k tokens per 1,000 calls: 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.

Together about 730k tokens per 1,000 calls An estimate from the code, not a measurement.

Tokens per 1,000 calls, by finding, and each one's share of the total

Plus 1 open question to confirm, listed after the findings.

Plus 3 other problems the audit found, listed after the findings. Not scored.

What this costs you

Every figure here is an estimate from the code, not a measurement. Findings can overlap (one failed call can show up in two), so the sum may count some tokens twice. Money is not part of the score. The table lists this app's findings first, largest first, then its open questions, then the questions for the server's administrator, then the findings the project already knows about, which are not in the totals.

FindingWhereTokens per 1,000 calls
LP-GE-03src/backend/core/providers/llm/foundry_iq.py:491250k output
LP-GE-03src/backend/core/providers/orchestrators/agent_framework.py:290250k output
LP-PC-02src/backend/core/providers/orchestrators/langgraph.py:186146k not cached
LP-PD-05src/frontend/src/api/streamChat.tsx:23384k prompt

To see this in money, add to leanprompt.yaml:

  • volume: {calls_per_month: N}: how many calls the app makes a month (with targets:, on each entry)
  • prices: per model: input, cached_input and output per 1M tokens (US dollars, or set currency), with source and checked date (or, self-hosted, engine: {prefill_tokens_per_second: N})

leanprompt never guesses a volume or a price. Your coding agent can look up the provider's current price page and add it with the date; how.

What's wrong and what to change

5 open, 0 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.

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.

Finding 1. src/backend/core/providers/llm/foundry_iq.py:491 high LP-GE-03 size is assumed

The model's own default is none, and the admin page's max tokens and temperature are not sent on this path.

What to 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 matters
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.
How big it is
The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: 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
Estimate
about 250k output tokens per 1,000 calls (estimate), if low effort uses about 500 fewer reasoning tokens per answer than medium
What the estimate assumes

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 to check the fix Run the same question set at medium and at low: reasoning_tokens per answer falls, the answer check passes, and no answer ends with status incomplete.

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.

Finding 2. src/backend/core/providers/orchestrators/agent_framework.py:290 high LP-GE-03 size is assumed

What to change
Use the same configurable effort and max_output_tokens as the LangGraph path, passed through ChatOptions.
Why it matters
Same as the LangGraph path: reasoning tokens are output tokens, and medium on every answer is above what a grounded answer usually needs.
How big it is
The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: reasoning_tokens per answer from the Foundry agent run at effort medium and at low on the same question set
Estimate
about 250k output tokens per 1,000 calls (estimate)
What the estimate assumes

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

How to check the fix Same question set at medium and low: reasoning_tokens fall and the answer check passes.

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.

Finding 3. src/backend/core/providers/orchestrators/langgraph.py:186 medium LP-PC-02

What to 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 matters
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)
What the estimate assumes

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.

How to check the fix Send turn 3 of a conversation twice: prompt_tokens_details.cached_tokens rises from about the system prompt size (or 0) to the system prompt plus the first exchange; the answer check passes.

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.

Finding 4. src/frontend/src/api/streamChat.tsx:233 low LP-PD-05 how often is assumed

What to change
Keep the last N exchanges (a setting, for example 10) in the orchestrator, dropping whole exchanges from the oldest end.
Why it matters
Each earlier answer is resent as input on every later turn; past a point it adds cost and little to a grounded answer.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: the distribution of message counts per /api/conversation request in App Insights
Estimate
about 84k prompt tokens per 1,000 calls (estimate), only from conversations longer than 10 exchanges
What the estimate assumes

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

How to check the fix A 15-turn conversation's request carries at most 10 earlier exchanges; follow-up questions in the answer check still resolve.

Open questions

Findings outside this repository, or whose behaviour the code cannot show. They still count in the score. Each says what to confirm.

Does the Foundry IQ knowledge base run an LLM query-planning step on every retrieval?

Finding 5. infra/scripts/post-provision/post_provision.py:424 low LP-GE-03

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.

To confirm
GET the cwyd-kb knowledge base and read retrievalReasoningEffort; check the retrieve activity array for a modelQueryPlanning entry and its token counts
Change, if confirmed
Set retrievalReasoningEffort explicitly in the knowledge base body (minimal if planning does not improve retrieval for typical questions, low otherwise).
Why it matters
Planning adds a model call per question on top of the answer call; minimal skips it.
Estimate
not estimated: depends on the stored effort
What the estimate assumes

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).

How to check the fix Retrieve activity shows no modelQueryPlanning entry at minimal, and answer-check recall stays the same.

Other problems the audit found

Problems the audit checked in the code that cost no tokens of their own, such as a spend meter that ignores cache tokens or a cut-off answer accepted as complete. They are not scored. Check each one before you change anything.

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

Note 1. src/frontend/src/pages/admin/Configuration/Configuration.tsx:219 LP-GE-17 high not scored

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.

What to 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.
Same problem as
finding 1

How to check the fix 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.

A cut-off answer is stored and shown as complete

Note 2. src/backend/core/providers/llm/foundry_iq.py:364 LP-GE-12 medium not scored

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.

What to 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.

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

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

Note 3. infra/bicep/main.bicep:184 not scored

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).

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

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

Fix it with your coding agent

Paste this into Claude Code, Codex, Cursor or any coding assistant. It will check each finding against your code and propose fixes one at a time, asking before it changes anything.

Please check and fix the LLM-call findings from a leanprompt audit of this repository.

1. If the leanprompt skills are not installed for you here, install them: npx leanprompt@0.1.0-dev.15 install
2. Read .leanprompt/findings.json and leanprompt-report.md. If they are missing, use the list below.
3. Check each finding against the code before you change anything. The audit can be wrong: if a finding does not hold, tell me why and leave that code alone.
4. Fix one finding at a time. Show me the change as a small diff and apply it only after I say yes.
5. Prove each fix with the measure-loop skill: a before and after on the same scenario. Ask me before running anything that sends real, billed requests.
6. When a fix is proved, set "fixed": true on its finding in .leanprompt/findings.json and run npx leanprompt@0.1.0-dev.15 score.

Findings, largest first:
1. LP-GE-03 at src/backend/core/providers/llm/foundry_iq.py:491: 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.
2. LP-GE-03 at src/backend/core/providers/orchestrators/agent_framework.py:290: 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.
3. LP-PC-02 at src/backend/core/providers/orchestrators/langgraph.py:186: 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.
4. LP-PD-05 at src/frontend/src/api/streamChat.tsx:233: 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.

Open questions (confirm before fixing):
- LP-GE-03 (infra/scripts/post-provision/post_provision.py:424): 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. 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 found (check each against the code first; not scored):
- 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]: 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. 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.
- A cut-off answer is stored and shown as complete (src/backend/core/providers/llm/foundry_iq.py:364) [LP-GE-12]: 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. 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.
- A second gpt-5-mini deployment for reasoning is provisioned but no code uses it (infra/bicep/main.bicep:184): 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). Change: Either route reason() to the reasoning deployment, or drop the deployment and its quota requirement from the template and docs.

Score

One number from 0 to 100 for how well this app avoids paying for the same tokens twice; higher is better. It is computed from the findings above (static) or from your usage log (measured).

80static
E, prefill reuse
0.95
S, prefix stability
1.00
G, generation waste
0.41
Default shares
0 of 5

Findings scored with severity defaults, not estimates. The fewer, the more the static score says about this app.

A static score is an estimate from the audit's findings, not a measurement.

Scored 2026-11-27 (the date on the machine that ran it).

Questions for the owner

These were not answered during the audit. Until they are, the page shows tokens only and ranks the advice without a priority.

  • Priority: which matters most for this app, cost, speed or quality (or weights)? Not set, so the advice uses equal weights. Answer with priority: in leanprompt.yaml.
  • Volume: how many calls does the app make a month? Answer with volume: {calls_per_month: N, source: "..."} in leanprompt.yaml.
  • Prices: what does each model cost (input, cached input, output per 1M tokens, with the source and the date it was read, and the currency if not US dollars)? Answer with prices: in leanprompt.yaml.