leanprompt 0.0.0-stage → 0.1.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE-DOCS +396 -0
- package/NOTICE +11 -0
- package/README.md +89 -2
- package/cli/dist/detect.d.ts +23 -0
- package/cli/dist/detect.js +219 -0
- package/cli/dist/evalAudit.d.ts +32 -0
- package/cli/dist/evalAudit.js +161 -0
- package/cli/dist/facts.d.ts +14 -0
- package/cli/dist/facts.js +43 -0
- package/cli/dist/forms.d.ts +23 -0
- package/cli/dist/forms.js +199 -0
- package/cli/dist/frontmatter.d.ts +10 -0
- package/cli/dist/frontmatter.js +32 -0
- package/cli/dist/help.d.ts +27 -0
- package/cli/dist/help.js +118 -0
- package/cli/dist/init.d.ts +78 -0
- package/cli/dist/init.js +358 -0
- package/cli/dist/install.d.ts +20 -0
- package/cli/dist/install.js +225 -0
- package/cli/dist/isMain.d.ts +6 -0
- package/cli/dist/isMain.js +18 -0
- package/cli/dist/lesson.d.ts +16 -0
- package/cli/dist/lesson.js +205 -0
- package/cli/dist/lint/facts.d.ts +7 -0
- package/cli/dist/lint/facts.js +163 -0
- package/cli/dist/lint/numbers.d.ts +26 -0
- package/cli/dist/lint/numbers.js +163 -0
- package/cli/dist/lint/rules.d.ts +20 -0
- package/cli/dist/lint/rules.js +170 -0
- package/cli/dist/log/logger.d.ts +49 -0
- package/cli/dist/log/logger.js +148 -0
- package/cli/dist/log/record.d.ts +56 -0
- package/cli/dist/log/record.js +117 -0
- package/cli/dist/main.d.ts +6 -0
- package/cli/dist/main.js +67 -0
- package/cli/dist/profile.d.ts +93 -0
- package/cli/dist/profile.js +372 -0
- package/cli/dist/report/cost.d.ts +55 -0
- package/cli/dist/report/cost.js +151 -0
- package/cli/dist/report/html.d.ts +81 -0
- package/cli/dist/report/html.js +555 -0
- package/cli/dist/report/template.html +269 -0
- package/cli/dist/score/calibrate.d.ts +65 -0
- package/cli/dist/score/calibrate.js +213 -0
- package/cli/dist/score/measured.d.ts +66 -0
- package/cli/dist/score/measured.js +191 -0
- package/cli/dist/score/static.d.ts +112 -0
- package/cli/dist/score/static.js +172 -0
- package/cli/dist/score/write.d.ts +29 -0
- package/cli/dist/score/write.js +247 -0
- package/forms/AGENTS.block.md +25 -0
- package/forms/opencode/commands/leanprompt-audit.md +10 -0
- package/forms/opencode/commands/leanprompt.md +8 -0
- package/forms/skills/generation-economy/SKILL.md +89 -0
- package/forms/skills/generation-economy/rules/LP-GE-01.md +93 -0
- package/forms/skills/generation-economy/rules/LP-GE-02.md +82 -0
- package/forms/skills/generation-economy/rules/LP-GE-03.md +87 -0
- package/forms/skills/generation-economy/rules/LP-GE-04.md +118 -0
- package/forms/skills/generation-economy/rules/LP-GE-05.md +84 -0
- package/forms/skills/generation-economy/rules/LP-GE-06.md +76 -0
- package/forms/skills/generation-economy/rules/LP-GE-07.md +84 -0
- package/forms/skills/generation-economy/rules/LP-GE-08.md +71 -0
- package/forms/skills/generation-economy/rules/LP-GE-09.md +79 -0
- package/forms/skills/generation-economy/rules/LP-GE-10.md +104 -0
- package/forms/skills/leanprompt/SKILL.md +48 -0
- package/forms/skills/leanprompt/fix.md +15 -0
- package/forms/skills/leanprompt/init.md +30 -0
- package/forms/skills/llm-call-audit/SKILL.md +169 -0
- package/forms/skills/llm-call-audit/call-shapes.md +99 -0
- package/forms/skills/llm-call-audit/presenting.md +72 -0
- package/forms/skills/llm-call-audit/report-template.md +113 -0
- package/forms/skills/lmwarden/SKILL.md +97 -0
- package/forms/skills/lmwarden/rules/LP-LW-01.md +73 -0
- package/forms/skills/lmwarden/rules/LP-LW-02.md +78 -0
- package/forms/skills/lmwarden/rules/LP-LW-03.md +73 -0
- package/forms/skills/measure-loop/SKILL.md +155 -0
- package/forms/skills/measure-loop/templates/stable-head.template.ts +38 -0
- package/forms/skills/measure-loop/templates/stable_head_template.py +40 -0
- package/forms/skills/prefill-cache/SKILL.md +66 -0
- package/forms/skills/prefill-cache/rules/LP-PC-01.md +103 -0
- package/forms/skills/prefill-cache/rules/LP-PC-02.md +80 -0
- package/forms/skills/prefill-cache/rules/LP-PC-03.md +75 -0
- package/forms/skills/prefill-cache/rules/LP-PC-04.md +79 -0
- package/forms/skills/prefill-cache/rules/LP-PC-05.md +68 -0
- package/forms/skills/prefill-cache/rules/LP-PC-06.md +71 -0
- package/forms/skills/prefill-cache/rules/LP-PC-07.md +97 -0
- package/forms/skills/prefill-cache/rules/LP-PC-08.md +67 -0
- package/forms/skills/prefill-cache/rules/LP-PC-09.md +75 -0
- package/forms/skills/prefill-cache/rules/LP-PC-10.md +76 -0
- package/forms/skills/prefill-cache/rules/LP-PC-11.md +72 -0
- package/forms/skills/prefill-cache/rules/LP-PC-12.md +73 -0
- package/forms/skills/prompt-diet/SKILL.md +69 -0
- package/forms/skills/prompt-diet/rules/LP-PD-01.md +79 -0
- package/forms/skills/prompt-diet/rules/LP-PD-02.md +73 -0
- package/forms/skills/prompt-diet/rules/LP-PD-03.md +65 -0
- package/forms/skills/prompt-diet/rules/LP-PD-04.md +77 -0
- package/forms/skills/prompt-diet/rules/LP-PD-05.md +71 -0
- package/forms/skills/prompt-diet/rules/LP-PD-06.md +68 -0
- package/models/anthropic-thinking.md +38 -0
- package/models/openai-reasoning.md +35 -0
- package/models/qwen.md +34 -0
- package/package.json +32 -4
- package/providers/anthropic.md +83 -0
- package/providers/deepinfra.md +46 -0
- package/providers/gemini.md +61 -0
- package/providers/openai.md +73 -0
- package/providers/openrouter.md +66 -0
- package/providers/sglang.md +41 -0
- package/providers/vllm.md +52 -0
- package/runtimes/http-clients.md +20 -0
- package/skills/_template/RULE.md +31 -0
- package/skills/generation-economy/SKILL.md +88 -0
- package/skills/generation-economy/rules/LP-GE-01.md +92 -0
- package/skills/generation-economy/rules/LP-GE-02.md +81 -0
- package/skills/generation-economy/rules/LP-GE-03.md +86 -0
- package/skills/generation-economy/rules/LP-GE-04.md +117 -0
- package/skills/generation-economy/rules/LP-GE-05.md +83 -0
- package/skills/generation-economy/rules/LP-GE-06.md +75 -0
- package/skills/generation-economy/rules/LP-GE-07.md +83 -0
- package/skills/generation-economy/rules/LP-GE-08.md +70 -0
- package/skills/generation-economy/rules/LP-GE-09.md +78 -0
- package/skills/generation-economy/rules/LP-GE-10.md +103 -0
- package/skills/leanprompt/SKILL.md +47 -0
- package/skills/leanprompt/fix.md +14 -0
- package/skills/leanprompt/init.md +29 -0
- package/skills/llm-call-audit/SKILL.md +168 -0
- package/skills/llm-call-audit/call-shapes.md +98 -0
- package/skills/llm-call-audit/presenting.md +71 -0
- package/skills/llm-call-audit/report-template.md +112 -0
- package/skills/lmwarden/SKILL.md +96 -0
- package/skills/lmwarden/rules/LP-LW-01.md +72 -0
- package/skills/lmwarden/rules/LP-LW-02.md +77 -0
- package/skills/lmwarden/rules/LP-LW-03.md +72 -0
- package/skills/measure-loop/SKILL.md +154 -0
- package/skills/measure-loop/templates/stable-head.template.ts +38 -0
- package/skills/measure-loop/templates/stable_head_template.py +40 -0
- package/skills/prefill-cache/SKILL.md +65 -0
- package/skills/prefill-cache/rules/LP-PC-01.md +102 -0
- package/skills/prefill-cache/rules/LP-PC-02.md +79 -0
- package/skills/prefill-cache/rules/LP-PC-03.md +74 -0
- package/skills/prefill-cache/rules/LP-PC-04.md +78 -0
- package/skills/prefill-cache/rules/LP-PC-05.md +67 -0
- package/skills/prefill-cache/rules/LP-PC-06.md +70 -0
- package/skills/prefill-cache/rules/LP-PC-07.md +96 -0
- package/skills/prefill-cache/rules/LP-PC-08.md +66 -0
- package/skills/prefill-cache/rules/LP-PC-09.md +74 -0
- package/skills/prefill-cache/rules/LP-PC-10.md +75 -0
- package/skills/prefill-cache/rules/LP-PC-11.md +71 -0
- package/skills/prefill-cache/rules/LP-PC-12.md +72 -0
- package/skills/prompt-diet/SKILL.md +68 -0
- package/skills/prompt-diet/rules/LP-PD-01.md +78 -0
- package/skills/prompt-diet/rules/LP-PD-02.md +72 -0
- package/skills/prompt-diet/rules/LP-PD-03.md +64 -0
- package/skills/prompt-diet/rules/LP-PD-04.md +76 -0
- package/skills/prompt-diet/rules/LP-PD-05.md +70 -0
- package/skills/prompt-diet/rules/LP-PD-06.md +67 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: LP-PD-06
|
|
3
|
+
title: Compact serialisation for data in the prompt
|
|
4
|
+
skill: prompt-diet
|
|
5
|
+
applies_to: [anthropic, openai, gemini, openrouter, deepinfra, vllm, sglang, any]
|
|
6
|
+
saves: prefill
|
|
7
|
+
severity: low
|
|
8
|
+
evidence:
|
|
9
|
+
- E11
|
|
10
|
+
- doc: https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview
|
|
11
|
+
checked: 2026-11-26
|
|
12
|
+
- doc: https://developers.openai.com/api/docs/guides/prompt-caching
|
|
13
|
+
checked: 2026-11-26
|
|
14
|
+
---
|
|
15
|
+
## Rule
|
|
16
|
+
Serialise the data the app puts into the prompt (tool results, records, retrieved rows, examples) compactly and the same way every time: no pretty-printing indentation, and a table or a list of rows instead of a list of objects that repeats every key.
|
|
17
|
+
|
|
18
|
+
## Why
|
|
19
|
+
Whitespace and repeated keys are tokens. `json.dumps(rows, indent=2)` adds a line break and indentation for every field, and a list of objects writes every key name once per row; a hundred rows with eight keys write each key a hundred times. The model reads the data just as well in compact JSON, or as a header line followed by rows. Anthropic counts `tool_result` content as input tokens ([providers/anthropic.md](../../../providers/anthropic.md)); data in the history is sent again on every later call ([providers/openai.md](../../../providers/openai.md)). Documented, not yet measured here; count the two forms with the provider's tokenizer before claiming a saving.
|
|
20
|
+
|
|
21
|
+
Serialisation is also a cache question. Whatever form you choose, produce it the same way every time (fixed key order, fixed separators), and never re-serialise data already in the history in a new form (LP-PC-04, LP-PC-06).
|
|
22
|
+
|
|
23
|
+
This rule is about data the app sends. Asking the model for a compact output format is about generated tokens, which the `generation-economy` skill covers (LP-GE-10 for structured output).
|
|
24
|
+
|
|
25
|
+
## Detect in code
|
|
26
|
+
Python:
|
|
27
|
+
```
|
|
28
|
+
rg -n 'json\.dumps\([^)]*indent\s*=|pprint\.pformat\(|yaml\.dump\(' -g '*.py'
|
|
29
|
+
```
|
|
30
|
+
Shapes: `json.dumps(result, indent=2)` as a tool result or in a prompt template; `df.to_json(orient="records")` for a large table; `pformat(obj)` in a prompt.
|
|
31
|
+
|
|
32
|
+
TS/JS:
|
|
33
|
+
```
|
|
34
|
+
rg -n 'JSON\.stringify\([^)]*,\s*(null|undefined)\s*,\s*\d' -g '*.{ts,tsx,js,mjs}'
|
|
35
|
+
```
|
|
36
|
+
Shapes: `JSON.stringify(data, null, 2)` in a tool handler or prompt builder.
|
|
37
|
+
|
|
38
|
+
Go:
|
|
39
|
+
```
|
|
40
|
+
rg -n 'json\.MarshalIndent\(' -g '*.go'
|
|
41
|
+
```
|
|
42
|
+
Shapes: `json.MarshalIndent(v, "", " ")` for a value that goes into a message.
|
|
43
|
+
|
|
44
|
+
## Fix
|
|
45
|
+
```python
|
|
46
|
+
# before: pretty-printed, every key on every row
|
|
47
|
+
content = json.dumps(rows, indent=2)
|
|
48
|
+
|
|
49
|
+
# after: compact, fixed separators and key order; for many uniform rows, a header and rows
|
|
50
|
+
content = json.dumps(rows, separators=(",", ":"), sort_keys=True, ensure_ascii=False)
|
|
51
|
+
|
|
52
|
+
COLS = ["id", "status", "total"]
|
|
53
|
+
content = json.dumps({"columns": COLS, "rows": [[r[c] for c in COLS] for r in rows]}, separators=(",", ":"))
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`sort_keys=True` keeps the bytes the same for the same data; if the app's key order carries meaning (a priority, a display order), keep a fixed order of your own instead.
|
|
57
|
+
|
|
58
|
+
## Don't break meaning
|
|
59
|
+
Compact JSON carries the same data; a header and rows changes the shape, so the prompt must say what the columns are, and the model must still be able to point at a row. Run the answer check with `measure-loop` on a fixed set of inputs, before and after: answers unchanged or better, including answers that quote or count the data. Data in the shared head (examples in the system prompt) is read from the cache, so change it there only if the saving outweighs one prefill of the head per route, once. Do not re-serialise or shorten data already in the history, and do not strip reasoning from it; stripping reasoning produced about 3x more generation (E11). What must stay byte-identical in the head and the history: [prefill-cache](../../prefill-cache/SKILL.md).
|
|
60
|
+
|
|
61
|
+
## Verify
|
|
62
|
+
(a) Provider usage: `usage.input_tokens` or `usage.prompt_tokens` on the call that carries the data falls by about the difference between the two forms; on later turns of the conversation `prompt_tokens` stays lower by the same amount, and `cached_tokens` on the next turn still covers the earlier history.
|
|
63
|
+
|
|
64
|
+
(b) leanprompt usage record: `prompt_tokens` falls for the call site; for the same data, the message's `ids.nodes` entry is equal across two runs (the serialisation is deterministic).
|
|
65
|
+
|
|
66
|
+
## Waste signal
|
|
67
|
+
Measured: the drop in `prompt_tokens` per call that carries the data, times those calls; the score does not count it, the report shows it as `tokens_per_1k.prompt`. Static: severity low for indented JSON or repeated keys in tool results or prompt data; medium when the data is large (hundreds of rows) and sits in an agent loop's history, where every later turn carries it.
|