Metadata-Version: 2.5
Name: templens
Version: 0.1.1
Summary: Lightweight validation for LLM prompt templates
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# Templens

Templens is a lightweight Python library for validating named variables in
LLM prompt templates before sending them to a model.

## Install

```shell
pip install templens
```

## Quick start

```python
from templens import Prompt

prompt = Prompt("Explain {topic} using {context}")

result = prompt.validate(
    variables={
        "topic": "RAG",
        "context": "Retrieval Augmented Generation",
    }
)

print(result.is_valid)  # True
print(result.missing_variables)  # []
```

Missing variables and names not used by the template both make the result
invalid:

```python
result = prompt.validate(variables={"topic": "RAG"})

print(result.is_valid)  # False
print(result.missing_variables)  # ['context']
print(result.unexpected_variables)  # []
```

`ValidationResult` also exposes `provided_variables`, and its string form
provides a human-readable summary. Escaped braces (`{{` and `}}`) are treated as
literal text. Templates must use named fields; automatic positional fields such
as `{}` and numbered positional fields such as `{0}` raise
`PromptTemplateError`.

## Development

```shell
uv sync --extra dev
uv run pytest
uv run ruff check .
```

Templens does not connect to an LLM and has no runtime dependencies.
