Skip to main content

lexigram-ai-prompt

AI prompt management for the Lexigram Framework — templates, composition, optimization


Overview

Type-safe prompt template management for the Lexigram AI framework. Build, version, compose, and auto-optimize prompts via DI — with injection protection, multi-format rendering, and a DSPy-inspired optimizer built in. Zero-config usage starts with sensible defaults.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-ai-prompt
# Optional extras
uv add "lexigram-ai-prompt[jinja2]"

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.prompt import PromptModule
from lexigram.ai.prompt.config import PromptConfig

@module(imports=[
    PromptModule.configure(
        PromptConfig(default_format="f_string", sanitize_inputs=True)
    )
])
class AppModule(Module):
    pass

app = Application(modules=[AppModule])
if __name__ == "__main__":
    app.run()

Configuration

Zero-config usage: Call PromptModule.configure() with no arguments to use defaults.

Option 1 — YAML file

# application.yaml
ai_prompt:
  enabled: true
  default_format: "f_string"
  sanitize_inputs: true
  strict_sanitizer: true
  max_variable_length: 0

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_PROMPT__DEFAULT_FORMAT=jinja2
# Environment variables for each field

Option 3 — Python

from lexigram.ai.prompt.config import PromptConfig
from lexigram.ai.prompt import PromptModule

config = PromptConfig(
    default_format="jinja2",
    sanitize_inputs=True,
    strict_sanitizer=True,
    max_variable_length=4096,
)
PromptModule.configure(config)

Config reference

Field Default Env var Description
enabled True LEX_AI_PROMPT__ENABLED Enable the AI prompt subsystem
default_format "f_string" LEX_AI_PROMPT__DEFAULT_FORMAT Rendering format when templates don't specify one
sanitize_inputs True LEX_AI_PROMPT__SANITIZE_INPUTS Scan variable values for injection patterns
strict_sanitizer True LEX_AI_PROMPT__STRICT_SANITIZER Raise on detected injection
max_variable_length 0 LEX_AI_PROMPT__MAX_VARIABLE_LENGTH Max variable value length in chars

Module Factory Methods

Method Description
PromptModule.configure(config) Configure with explicit config
PromptModule.stub() Minimal config for testing

Key Features

  • Template types: StringPromptTemplate, ChatPromptTemplate, FewShotPromptTemplate, PartialPromptTemplate
  • Rendering formats: f_string, jinja2, dollar, and simple templates
  • Registry: Named prompt lookup via PromptRegistry
  • Versioning: VersionedPromptStore with history and rollback
  • Composition: PromptPipeline (sequential) and ConditionalPrompt (branching)
  • Optimizer: DSPy-inspired automatic prompt improvement with BOOTSTRAP_FEW_SHOT, TEMPLATE_REFINEMENT, and ENSEMBLE strategies

Testing

async with Application.boot(modules=[PromptModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/prompt/module.py PromptModule.configure(), .stub()
src/lexigram/ai/prompt/config.py PromptConfig
src/lexigram/ai/prompt/template/string.py StringPromptTemplate
src/lexigram/ai/prompt/template/chat.py ChatPromptTemplate
src/lexigram/ai/prompt/template/few_shot.py FewShotPromptTemplate
src/lexigram/ai/prompt/rendering/engine.py PromptRenderer, RenderFormat
src/lexigram/ai/prompt/registry/registry.py PromptRegistry
src/lexigram/ai/prompt/registry/versioned.py VersionedPromptStore
src/lexigram/ai/prompt/composition/pipeline.py PromptPipeline
src/lexigram/ai/prompt/optimization/optimizer.py PromptOptimizer
src/lexigram/ai/prompt/di/provider.py PromptProvider

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexigram_ai_prompt-0.1.3006-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_prompt-0.1.3006-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_prompt-0.1.3006-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2730c29805f3365da6f65145afa9c30bbe703771de3fb1224a186d7c7d51e6
MD5 64061a7f78f058e620f21c133037767c
BLAKE2b-256 6c3668c4c107e9e324ce5141a2595f3854df3b1fdbcd9014a5b45dd00fc89c7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page