ractogateway.prompts
ractogateway.prompts — RACTO Prompt Engine.
Provides the RactoPrompt Pydantic model that enforces structured prompt
definition via the RACTO principle (Role, Aim, Constraints, Tone, Output)
and compiles it into an optimized, anti-hallucination system prompt.
- class ractogateway.prompts.RactoPrompt(**data)[source]
Bases:
BaseModelA strictly validated RACTO prompt definition.
- Parameters:
role (str) – A sentence (or short paragraph) describing who the LLM is.
aim (str) – A clear statement of the task objective.
constraints (list[str]) – Hard rules the model must obey. At least one is required.
tone (str) – The desired communication style (e.g. “Professional and concise”).
output_format (str | type[BaseModel]) – Either a format keyword (
"json","text","markdown"), a free-form format description, or a Pydantic model class whose JSON Schema will be embedded in the prompt.context (str | None) – Optional extra context paragraph injected between AIM and CONSTRAINTS. Useful for passing domain-specific background knowledge that the model needs to reason about.
examples (list[dict[str, str]] | None) – Optional list of example input/output pairs that are included in the prompt to steer the model via few-shot learning.
anti_hallucination (bool) – When True (the default), the compiler appends explicit anti-hallucination directives at the end of the prompt.
Notes
- Legacy compatibility:
Older RactoGateway versions accepted
instructionswithout the full RACTO field set. That shape is still accepted and mapped toaimwith sensible defaults for missing RACTO fields.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- role: str
- aim: str
- tone: str
- anti_hallucination: bool
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- compile()[source]
Compile the RACTO fields into an optimized system prompt string.
The resulting prompt is structured into clearly delimited sections so that the LLM can parse each instruction block unambiguously.
- Return type:
- Returns:
str – A ready-to-use system prompt.
- to_messages(user_message, *, attachments=None, provider='generic')[source]
Return a ready-to-send message list for a given LLM provider.
- Parameters:
user_message (
str) – The end-user’s query or input.attachments (
list[RactoFile] |None) –Optional list of
RactoFileobjects to send alongside the text message. Accepted inputs per file:File path — use
RactoFile.from_path():RactoFile.from_path("/tmp/diagram.png")
Raw bytes — use
RactoFile.from_bytes():RactoFile.from_bytes(img_bytes, "image/png")
Each file is re-encoded into the content-block schema expected by the target provider (
image_urlfor OpenAI,image/documentfor Anthropic,inline_datafor Google,imageslist for Ollama).provider (
str) – One of"openai","anthropic","google","ollama", or"generic". Controls the system-role key name and the content-block format used for attachments.
- Return type:
- Returns:
list[dict[str, Any]] – A list of message dicts suitable for the provider’s API.