Python definitions registry: token expansion, the prompt index, and grain - #261
Open
jat255 wants to merge 2 commits into
Open
Python definitions registry: token expansion, the prompt index, and grain#261jat255 wants to merge 2 commits into
jat255 wants to merge 2 commits into
Conversation
The registry surface commons owns whatever data-dict eventually provides:
{{name}} and {{table::name}} expansion, the kind index for the prompt,
grain metadata for call_metrics' mixed-grain guard, and the check that a
definition's table is one the source exposes.
Everything consumes ExportRecord and nothing reaches into an expression
parser or a typed IR. That rule is what makes replacing this with a shared
data-dict interface a deletion rather than a rewrite, and it is why the
registry can be built and tested before the compiler exists.
The dictionary's first-touch entry and its retrieval chunks now render a
table's definitions, which the reader left as a marked seam. Both show
compiled SQL rather than the authored expression, since the expression is
in data-dict's language and the model writes SQL.
Tests run the registry against tests/shared/definitions.json as well as
against hand-built records: every definition data-dict produced expands to
its own compiled SQL, and each kind is one the index groups. This is the
first Python code to consume that contract.
…e gist Four defects, each reproduced first. Token resolution ran against SQL that earlier expansions had already rewritten, so a definition whose compiled SQL named another table brought that table into scope for a later bare token. Every token now resolves against the query as written, and substitution happens afterwards. Retrieval chunks carried only the kind and type, so a retrieved definition named a token without saying what it expands to. They carry the same gist as the first-touch entry now, which is compiled SQL and notes, never the authored expression. An absent type reached the prompt as the word "None". data-dict omits the type when no single one is inferred, so it is left out rather than printed. pkg-r loses the entire gist in this case, filed as #259. The index cap counted line lengths but not the newlines joining them, so the result could exceed the cap. It measures the joined text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fifth PR of M2. Adds the definitions registry, the surface commons owns until data-dict provides one. Closes the registry issue plus the two items that moved to it from the dictionary reader.
Base is #255. Review that first; the diff here is only the registry.
What it does
{{name}}and{{table::name}}tokens inrun_sqlqueries.call_metrics' mixed-grain guard needs.Everything consumes
ExportRecord; nothing reaches into an expression parser or a typed IR. When a shared data-dict interface arrives, swapping it in is a deletion rather than a rewrite. That is why the registry exists, and why it is tested before the compiler is.First Python code to assert the shared contract
Tests run the registry over
tests/shared/definitions.jsonas well as hand-built records. They check that every definition data-dict produced expands to its own compiled SQL, that every kind is one the index groups, and that the grain flags reach the records. #255 landed that fixture with only R asserting it; this is the Python half.Four defects found in review
Each was reproduced before fixing.
sum(returns.x)putreturnsin scope for a later bare token, defeating the check that keeps a token bound to its own table. Tokens now resolve against the query as written.None. data-dict omitstypewhen it cannot infer a single one, so it is left out of the prompt too.Three R defects this surfaced
Filed rather than fixed here, since
pkg-ris a separate package and each fix needs its own R reviewer summary. The first two mean the implementations disagree on observable behavior until R is fixed.expand_definitions()directly.definition_gist()returns an empty string for a definition with no inferred type, dropping the compiled SQL and the notes rather than just the type.No shared fixture for these yet. A fixture would have to pin a single behavior, and R would fail it immediately; the plan is to fix R first and pin the agreement then.
Verification
325 tests, ruff and pyrefly clean.