promplate-inspect
Inspect input variables used in a promplate template.
Useful when instructing an LLM to produce structural data with certain fields, or for you to quickly understand the data structure a template expects.
pip install promplate-inspect
Usage
from promplate import Template
from promplate_inspect import find_input_variables_in_template
t = Template("""
{#
import a as b
from c import d
#}
{{ e }}
{{ f.strip() }}
{{ list }}
{#
g += 1
h = { **h }
#}
{% for i in func() %}
{{ [ j for j in range(i) ] }}
{% endfor %}
""")
find_input_variables_in_template(t) # {'e', 'f', 'g', 'h'}
Note that it excludes builtin names by default.
If you allow LLM to output variables like dict or list,
you can specify the second parameter exclude_builtins:
find_input_variables_in_template(t, exclude_builtins=False) # {'e', 'f', 'g', 'h', 'list'}
As you see, variables that defined explicitly in the templates are not filtered out as expected.
And functions above like func and range are always excluded because LLM can never out callable instances typically.
Limitations
- This parser is still work in progress. If you includes any of these code in your
{{ }}/{# #}tags, the result may be wrong:- Parameters of function. Inspecting
{{ (lambda x: x + 1)(y) }}should output{'y'}but outputs{'x', 'y'}for now. - Similarly, variables defined in
withstatements andexceptstatements are not excluded for now.
- Parameters of function. Inspecting
- This implementation use
astto parse the template. It never run the code, so these monkey patches won't be tracked:- Getting variables from
globals()/locals()/__main__won't be finded. Such asnamewon't be found in{{ locals()["name"] }}. - Assigning values to
globals()/locals()/__main__won't be excluded. Even if you wrote{# globals().setdefault("name", "value") #},namewill still be found in{{ name }}.
- Getting variables from
- For now it only find variables in the given template itself. It don't find variables needed in the components used by it.
Metadata
Release files for promplate-inspect 0.0.2.2
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 | Actions |
|---|---|---|---|---|
| promplate_inspect-0.0.2.2.tar.gz | 3.0 kB | Without provenance | Details for promplate_inspect-0.0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promplate_inspect-0.0.2.2-py3-none-any.whl | Python 3 | none | any | Details for promplate_inspect-0.0.2.2-py3-none-any.whl |
Total release size: 6.1 kB
Release files / promplate_inspect-0.0.2.2.tar.gz
| Download URL | promplate_inspect-0.0.2.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7a47c6189836970b286c1d67f10fd4ecbd97a9e04c629add9d05fa42d615cb2
|
|
BLAKE2b-256 checksum How to use checksums |
6f5c9373b3f6aa7ab541158a7e242041f1a55a360b0585e2514aeaca9d9479a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / promplate_inspect-0.0.2.2-py3-none-any.whl
| Download URL | promplate_inspect-0.0.2.2-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d98f545bdfcbf19d062f4b44c76a4a457bca0221eea126ac8f446150b951444
|
|
BLAKE2b-256 checksum How to use checksums |
a48574a6a363f9765e14db9900ef89b6b43e7164e8a8572382c10e9b52cae95c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for promplate-inspect 0.0.2.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.