The page leanprompt report --html writes for sqlchat/sqlchat at commit 85af0b4, audited 2026-11-28. 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 sqlchat/sqlchat

leanprompt audit of sqlchat/sqlchat

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.

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

The biggest, at src/utils/openai.ts:27, about 180k tokens per 1,000 calls: the number of tables put in the system prompt is decided by a budget that starts from the length of the current question (line 27, test at line 48).

Together about 240k 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 4 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-PC-02src/utils/openai.ts:27180k not cached
LP-PD-02src/components/ConversationView/index.tsx:19460k 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

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

The number of tables put in the system prompt is decided by a budget that starts from the length of the current question (line 27, test at line 48).

Finding 1. src/utils/openai.ts:27 medium LP-PC-02 how often is assumed

A longer question leaves room for fewer tables, so for a large schema the system prompt is different on different turns: tables the model saw earlier disappear, and the cached prefix (system prompt, then history) does not match.

What to change
Spend the table budget without the current question (use a fixed share of max_token), so the system prompt is the same for the whole conversation.
Why it matters
The system prompt is the first thing in every request; when it changes, the history after it cannot be read from the cache, and the model sees a different set of tables from turn to turn.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how many selected schemas exceed half of the model's max_token budget (only those lose tables, and so vary)
Estimate
about 180k prompt tokens per 1,000 calls not served from cache
What the estimate assumes

1 in 10 calls hits a schema larger than the budget and changes the table list; about 1,800 tokens of prefix lost each time

How to check the fix Ask two questions of different length on a schema larger than max_token/2 and compare the system message of both requests: today the table lists differ, after the fix they are identical.

The question is saved to the message list before the history is read back, so the history loop already contains it; the code then pushes the same question again as the last message.

Finding 2. src/components/ConversationView/index.tsx:194 low LP-PD-02

Every request ends with the same user message twice.

What to change
Build the history from the list as it was before the question was added (or skip the message whose id is userMessage.id in the loop at line 174).
Why it matters
Every call sends the newest question twice and counts it twice against the history budget, so a little less history fits.
Estimate
about 60k prompt tokens per 1,000 calls (60-token question)
What the estimate assumes

an average question of about 60 tokens; every call goes through this path

How to check the fix Log formatedMessageList.length before the fetch: it is history + 3 today (system, history, question, question) and history + 2 after the fix; the last two entries are no longer equal.

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.

Default and listed models were shut down on 2026-10-23

Note 1. src/store/setting.ts:13 LP-GE-13 high not scored

The default model is gpt-3.5-turbo (setting.ts:13, and getModel returns it when no name is sent, model.ts:67-69). gpt-4 and gpt-4-turbo, also offered in the settings (OpenAIApiConfigView.tsx), have the same shutdown date. OpenAI's deprecations page lists gpt-3.5-turbo, gpt-4 and gpt-4-turbo as shut down on Oct 23, 2026 (replacements gpt-5.6-terra and gpt-5.6-sol).

What to change
Change the default and the list in setting.ts, model.ts and OpenAIApiConfigView.tsx to models OpenAI still serves; keep the per-model cost_per_call table in step.

How to check the fix A request with the default settings against api.openai.com returns 200, not model_not_found.

A cut-off answer is stored as complete

Note 2. src/pages/api/chat.ts:146 LP-GE-12 medium not scored

The stream parser forwards delta.content and never reads finish_reason, and the request sets no max_tokens. An answer that stops for length is marked DONE (ConversationView/index.tsx:276) and sent back as history on the next turn.

What to change
Read choices[0].finish_reason; on length, mark the message so the user sees it was cut.

How to check the fix Force a small max_tokens on a test endpoint: the message shows a cut-off marker instead of DONE.

Stream is never closed when the provider sends no [DONE]

Note 3. src/pages/api/chat.ts:140 not scored

controller.close() is only reached on a [DONE] event, so providers that omit it leave the client hanging in LOADING.

What to change
Close the controller after the for-await loop ends.
Already reported
Issue #176 open; fix PR #186 (octo-patch) was closed by the maintainer on 2026-09-17 without a comment. https://github.com/sqlchat/sqlchat/issues/176

Quota is a flat per-call cost, charged before generation

Note 4. src/pages/api/usage.ts:29 not scored

addUsage adds model.cost_per_call regardless of tokens, and chat.ts:161-167 charges it before the stream is read. There is no token meter, so LP-GE-11 (cache tokens) does not apply; a design choice, not a bug.

What to change
No change needed; note only: if a token-based quota is wanted later, meter prompt, cached and output tokens from the stream's usage field.

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-PC-02 at src/utils/openai.ts:27: The number of tables put in the system prompt is decided by a budget that starts from the length of the current question (line 27, test at line 48). A longer question leaves room for fewer tables, so for a large schema the system prompt is different on different turns: tables the model saw earlier disappear, and the cached prefix (system prompt, then history) does not match.
2. LP-PD-02 at src/components/ConversationView/index.tsx:194: The question is saved to the message list before the history is read back, so the history loop already contains it; the code then pushes the same question again as the last message. Every request ends with the same user message twice.

Other problems found (check each against the code first; not scored):
- Default and listed models were shut down on 2026-10-23 (src/store/setting.ts:13) [LP-GE-13]: The default model is gpt-3.5-turbo (setting.ts:13, and getModel returns it when no name is sent, model.ts:67-69). gpt-4 and gpt-4-turbo, also offered in the settings (OpenAIApiConfigView.tsx), have the same shutdown date. OpenAI's deprecations page lists gpt-3.5-turbo, gpt-4 and gpt-4-turbo as shut down on Oct 23, 2026 (replacements gpt-5.6-terra and gpt-5.6-sol). Change: Change the default and the list in setting.ts, model.ts and OpenAIApiConfigView.tsx to models OpenAI still serves; keep the per-model cost_per_call table in step.
- A cut-off answer is stored as complete (src/pages/api/chat.ts:146) [LP-GE-12]: The stream parser forwards delta.content and never reads finish_reason, and the request sets no max_tokens. An answer that stops for length is marked DONE (ConversationView/index.tsx:276) and sent back as history on the next turn. Change: Read choices[0].finish_reason; on length, mark the message so the user sees it was cut.
- Stream is never closed when the provider sends no [DONE] (src/pages/api/chat.ts:140): controller.close() is only reached on a [DONE] event, so providers that omit it leave the client hanging in LOADING. Change: Close the controller after the for-await loop ends.
- Quota is a flat per-call cost, charged before generation (src/pages/api/usage.ts:29): addUsage adds model.cost_per_call regardless of tokens, and chat.ts:161-167 charges it before the stream is read. There is no token meter, so LP-GE-11 (cache tokens) does not apply; a design choice, not a bug. Change: No change needed; note only: if a token-based quota is wanted later, meter prompt, cached and output tokens from the stream's usage field.

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

92static
E, prefill reuse
0.87
S, prefix stability
1.00
G, generation waste
0.00
Default shares
0 of 2

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-28 (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.