Expand description
Condensing JSON: keep the shape, sample the values.
§Why the schema is the part worth keeping
A condensate is typed, not a blob of text (US-0104), and for an API response
the type is the useful part. A model that knows the response is
{ users: [{ id: integer, email: string }], next_cursor: string|null } can
plan its next step without reading five thousand users. One shown the first
two hundred users and nothing else has to guess whether next_cursor exists
at all.
So the schema is retained unconditionally and the values compete for what is left. Under a cap that fits nothing else, a JSON condensate is still a complete and accurate description of the response’s shape.
§Secrets are removed, not condensed
Redaction happens before anything else and is not subject to the cap. A
token that fits is worse than one that does not: it reaches the model, the
ledger, and any sink the ledger feeds (US-1004 exports spans to a collector).
ARCHITECTURE.md §11 requires secrets never to be journalled and US-1005
asks for a redaction test to prove it; this is the layer where API responses
get that treatment.
Matching is by field name against the conventions credentials actually use, plus a check on the value’s own shape for the formats that are unmistakable. It is deliberately eager: a false positive costs a field the model probably did not need, and a false negative costs a credential.
§What gives way under pressure
- Array samples, shortest first — the element count is kept regardless, so “five thousand users” survives even when no user does.
- Depth, outermost last — a nested object becomes a named type, and the path that was elided is listed.
- The sample entirely, leaving the schema.
The counts and the elided paths are what stop this from being lossy in the dangerous sense: the model can always see that there was more.
Structs§
- Json
Slicer - Condenses JSON responses.
Constants§
- JSON_
SCHEMA - The schema a JSON condensate declares.
- REDACTED
- What a redacted value is replaced with.
Functions§
- infer
- A schema inferred from a value.
- is_
secret_ key - Whether a field name suggests a credential.
- looks_
like_ secret - Whether a value is unmistakably a credential whatever it is called.