Prompt Configuration

Prompt configuration loading module.

This module provides functionality to load and validate prompt configurations from YAML files for LLM data generation tasks.

class spacylize.prompt_config.PromptMessage(*, role, content)[source]

Bases: BaseModel

A single prompt message with role and content.

Parameters:
  • role (Literal['system', 'user', 'assistant'])

  • content (str)

role

The role of the message (system, user, or assistant).

Type:

Literal[‘system’, ‘user’, ‘assistant’]

content

The text content of the message.

Type:

str

role: Literal['system', 'user', 'assistant']
content: str
model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.PromptConfig(*, system, user)[source]

Bases: BaseModel

Configuration model for prompt templates.

Defines the structure for prompt configurations including system and user messages for LLM interactions.

Parameters:
system

System prompt message for setting LLM behavior.

Type:

spacylize.prompt_config.PromptMessage

user

User prompt message for the main task instruction.

Type:

spacylize.prompt_config.PromptMessage

system: PromptMessage
user: PromptMessage
model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.NERExample(*, text, explanation=None)[source]

Bases: BaseModel

Example for NER few-shot learning.

Parameters:
  • text (str)

  • explanation (str | None)

text

Example text with inline [ENTITY](LABEL) annotations.

Type:

str

explanation

Optional explanation of what this example demonstrates.

Type:

str | None

text: str
explanation: str | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.NERStructuredConfig(*, task='ner', entities, domain, tone='professional', length='1-2 paragraphs', language='en', temperature=0.7, constraints=[], examples=[])[source]

Bases: BaseModel

Structured configuration for NER tasks.

Users specify high-level parameters and templates generate the prompts.

Parameters:
  • task (Literal['ner'])

  • entities (Annotated[List[str], MinLen(min_length=1)])

  • domain (str)

  • tone (str | None)

  • length (str | None)

  • language (str | None)

  • temperature (Annotated[float | None, Ge(ge=0.0), Le(le=1.0)])

  • constraints (List[str] | None)

  • examples (List[NERExample] | None)

task

Task type identifier (must be “ner”).

Type:

Literal[‘ner’]

entities

List of entity labels to include in generated text.

Type:

List[str]

domain

Description of the domain/topic for generated text.

Type:

str

tone

Writing style (e.g., “professional”, “casual”, “technical”).

Type:

str | None

length

Expected length of generated text (e.g., “2-3 sentences”).

Type:

str | None

language

ISO language code (e.g., “en”, “de”, “es”).

Type:

str | None

temperature

LLM temperature for generation (0.0-1.0).

Type:

float | None

constraints

Additional rules or constraints for generation.

Type:

List[str] | None

examples

Few-shot examples to guide the LLM.

Type:

List[spacylize.prompt_config.NERExample] | None

task: Literal['ner']
entities: List[str]
domain: str
tone: str | None
length: str | None
language: str | None
temperature: float | None
constraints: List[str] | None
examples: List[NERExample] | None
classmethod validate_entities(v)[source]

Ensure at least one entity is specified.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.TextCatCategory(*, name, description)[source]

Bases: BaseModel

Category definition for text classification.

Parameters:
  • name (str)

  • description (str)

name

Category name/label.

Type:

str

description

Description of what this category includes.

Type:

str

name: str
description: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.TextCatExample(*, text, category)[source]

Bases: BaseModel

Example for TextCat few-shot learning.

Parameters:
  • text (str)

  • category (str)

text

Example text to classify.

Type:

str

category

The correct category for this text.

Type:

str

text: str
category: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spacylize.prompt_config.TextCatStructuredConfig(*, task='textcat', categories, domain, tone='professional', length='2-3 sentences', language='en', temperature=0.7, constraints=[], examples=[])[source]

Bases: BaseModel

Structured configuration for text classification tasks.

Users specify high-level parameters and templates generate the prompts.

Parameters:
  • task (Literal['textcat'])

  • categories (Annotated[List[TextCatCategory], MinLen(min_length=2)])

  • domain (str)

  • tone (str | None)

  • length (str | None)

  • language (str | None)

  • temperature (Annotated[float | None, Ge(ge=0.0), Le(le=1.0)])

  • constraints (List[str] | None)

  • examples (List[TextCatExample] | None)

task

Task type identifier (must be “textcat”).

Type:

Literal[‘textcat’]

categories

List of category definitions.

Type:

List[spacylize.prompt_config.TextCatCategory]

domain

Description of the domain/topic for generated text.

Type:

str

tone

Writing style (e.g., “professional”, “casual”, “marketing”).

Type:

str | None

length

Expected length of generated text (e.g., “2-3 sentences”).

Type:

str | None

language

ISO language code (e.g., “en”, “de”, “es”).

Type:

str | None

temperature

LLM temperature for generation (0.0-1.0).

Type:

float | None

constraints

Additional rules or constraints for generation.

Type:

List[str] | None

examples

Few-shot examples to guide the LLM.

Type:

List[spacylize.prompt_config.TextCatExample] | None

task: Literal['textcat']
categories: List[TextCatCategory]
domain: str
tone: str | None
length: str | None
language: str | None
temperature: float | None
constraints: List[str] | None
examples: List[TextCatExample] | None
classmethod validate_categories(v)[source]

Ensure at least two categories are specified.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

spacylize.prompt_config.load_prompt_config(path, output_folder=None)[source]

Load and render structured prompt configuration from YAML.

This function loads a structured configuration file and uses Jinja2 templates to render the final system and user prompts. The structured format allows users to specify high-level parameters (entities, domain, tone, etc.) while templates handle the prompt engineering.

Parameters:
  • path (Path) – Path to the structured config YAML file.

  • output_folder (Path | None) – Optional folder to write rendered prompts for user verification.

Returns:

PromptConfig with rendered system and user prompts.

Raises:

RuntimeError – If the configuration is invalid or missing required fields.

Return type:

PromptConfig