semql-prompt
LLM-facing prompt rendering for a semql
Catalog.
semql's compiler is pure — it turns a SemanticQuery into SQL and never
renders a prompt. This package is the rendering layer on top:
- Four-role prompt fragments —
build_planner_prompt_fragment,build_router_prompt_fragment,build_presenter_prompt_fragment,build_drilldown_prompt_fragment,build_query_generator_prompt_fragment. - Cacheable segments —
CatalogPrompt(viewer-invariantstatic+ per-vieweroverlay) for prompt-cache breakpoints, plusprompt_hash. - Tool-description projection —
to_openai_tools/to_langchain_tools/to_openai_functionfor function-calling clients, andto_bedrock_converse_toolsfor the Bedrock Converse API (object-rootedinputSchema). - Prompt-token budgeting —
PromptBudget,apply_budget,estimate_tokens; every result states whether its estimate actually fits.
Install
pip install semql-prompt
Quick start
The catalog-level conveniences take the catalog as their first argument:
from semql import Catalog
from semql_prompt import planner_prompt, planner_prompt_segments, prompt_hash, to_openai_tools
text = planner_prompt(
catalog,
viewer=viewer,
instructions="Prefer concise labels.", # trusted application policy
)
segs = planner_prompt_segments(catalog)
key = prompt_hash(catalog)
tools = to_openai_tools(catalog, viewer=viewer)
Role builders keep mandatory query, authorization, and untrusted-data guidance
while accepting optional trusted instructions. With no explicit router
scope_to, the Query Generator can use the existing catalog retriever
(user_query, retriever, top_k) to select relevant cubes.
Budgeting uses an approximate chars/4 estimate. Always check
BudgetResult.fits; it is False when protected cubes or mandatory
instructions alone exceed the requested limit:
from semql_prompt import PromptBudget
result = PromptBudget(max_tokens=4_000).apply(
text,
protected_cubes=frozenset({"orders"}),
)
if not result.fits:
raise ValueError("required prompt content exceeds the configured budget")
For the lower-level per-role fragment builders, see API reference.
Prompt-budget results
PromptBudget.apply(text) reports token_count, count_source
("heuristic" by default), and explicit fits status alongside
was_truncated and dropped. The default count is only the package's
chars/4 heuristic. Supply a model-specific counter without adding a dependency:
from semql_prompt import PromptBudget
result = PromptBudget(max_tokens=8_000).apply(
prompt,
count_tokens=model_tokenizer.count,
)
The same count_tokens callback is accepted by apply_budget. Trimming
removes known optional catalog sections; if required or otherwise untrimmable
text remains over budget, it is preserved and fits is False.
License
BSD-3-Clause.
Metadata
Release files for semql-prompt 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| semql_prompt-0.10.0.tar.gz | 29.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| semql_prompt-0.10.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.2 kB
Release files / semql_prompt-0.10.0.tar.gz
| Download URL | semql_prompt-0.10.0.tar.gz |
|---|---|
| Size | 29.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb2b3bf7e75b7239cdd8b9921cfe1986d5fe822a2acb3172601351f198b01336
|
|
BLAKE2b-256 checksum How to use checksums |
235de3155ad9cfce8f2c1d13c7c57611cb60aec00d65830e12b11804bf473d42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.
Transparency logRelease files / semql_prompt-0.10.0-py3-none-any.whl
| Download URL | semql_prompt-0.10.0-py3-none-any.whl |
|---|---|
| Size | 32.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94117a0ebece411ce6a34c4910dc182a317f5d1c7ee4a38be8b880ec8a71d941
|
|
BLAKE2b-256 checksum How to use checksums |
8b07a811add3f34618866cf57ba2568ece462c27854016ce8aff78dbff47ad35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.
Transparency logSecurity for semql-prompt 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for semql_prompt-0.10.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.