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 Distribution

lexigram_ai_prompt-0.1.2.tar.gz (70.3 kB view details)

Uploaded Source

Built Distribution

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

lexigram_ai_prompt-0.1.2-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_prompt-0.1.2.tar.gz.

File metadata

  • Download URL: lexigram_ai_prompt-0.1.2.tar.gz
  • Upload date:
  • Size: 70.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_ai_prompt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3c0b9bd0188c0f0a51c07fb51483732828b32b37c7cdc5e56772516d3c8f3bda
MD5 605f3826331e46a493d204e765467993
BLAKE2b-256 dac8fb851d0b69311fa9e5337b339101f3fa5e8f3d66702cba2a9db9e4a8a70c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lexigram_ai_prompt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4960464ec22c25fdd29f3c441c28cca417e4d1ef532dc219860cd9c6e21dee76
MD5 88c90d858675ecd0f388d22a57895bed
BLAKE2b-256 6bf63b26eb437d741cae50b858704486a780257bedcca67e61c4a46829c475eb

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