Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-prompt/src/lexigram/ai/prompt/config.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1"""Prompt configuration for the Lexigram framework.""" 

2 

3from __future__ import annotations 

4 

5from dataclasses import dataclass 

6from typing import ClassVar, cast 

7 

8from lexigram.ai.prompt.constants import ( 

9 DEFAULT_RENDER_FORMAT, 

10 ENV_NESTED_DELIMITER, 

11 ENV_PREFIX, 

12) 

13from lexigram.ai.prompt.rendering.engine import RenderFormat 

14from lexigram.config.base import BaseConfig 

15from lexigram.validation import ConfigDict, Field 

16 

17 

18@dataclass(init=False) 

19class PromptConfig(BaseConfig): 

20 """Configuration for the prompt management system. 

21 

22 Attributes: 

23 default_format: Default rendering format. One of the 

24 :class:`~lexigram.ai.prompt.rendering.engine.RenderFormat` 

25 values (``"f_string"``, ``"jinja2"``, ``"dollar"``, or 

26 ``"simple"``). Applied to templates that don't 

27 specify their own format. 

28 sanitize_inputs: When ``True``, apply :class:`~lexigram.ai.prompt.rendering.sanitizer.InputSanitizer` 

29 to all user-supplied variable values. 

30 strict_sanitizer: When ``True``, detected injection patterns raise an 

31 error. When ``False``, they only generate warnings. 

32 max_variable_length: Global default for maximum allowed variable value 

33 length in characters. ``0`` means unlimited. 

34 """ 

35 

36 config_section: ClassVar[str] = "ai_prompt" 

37 

38 model_config: ClassVar[ConfigDict] = cast( 

39 "ConfigDict", 

40 { 

41 "env_prefix": ENV_PREFIX, 

42 "env_nested_delimiter": ENV_NESTED_DELIMITER, 

43 "extra": "ignore", 

44 }, 

45 ) 

46 

47 enabled: bool = Field(default=True, description="Enable the AI prompt subsystem") 

48 

49 default_format: RenderFormat = Field(default=DEFAULT_RENDER_FORMAT) 

50 """Rendering format applied to templates that don't specify their own.""" 

51 

52 sanitize_inputs: bool = Field(default=True) 

53 """Enable automatic injection scanning on template variables.""" 

54 

55 strict_sanitizer: bool = Field(default=True) 

56 """Raise on detected injection when ``True``; warn-only when ``False``.""" 

57 

58 max_variable_length: int = Field(default=0, ge=0) 

59 """Global max variable length in chars. ``0`` = unlimited.""" 

60 

61 

62__all__ = ["PromptConfig"]