Skip to main content
Instruction component for instruct/validate/repair loops. Instruction is the primary component type used with MelleaSession.instruct. It packages a task description, a list of [Requirement](../../core/requirement#class-requirement) constraints, optional in-context-learning examples, a grounding context dict, user variables for Jinja2 template interpolation, and output/input prefix overrides into a single renderable unit. The session’s sampling strategy evaluates each requirement against the model’s output and may repair or resample until all requirements pass.

Classes

CLASS Instruction

The Instruction in an instruct/validate/repair loop. Args:
  • description: The task description shown to the model.
  • requirements: Constraints the output must satisfy.
  • icl_examples: In-context-learning examples.
  • grounding_context: Named context passages injected into the prompt.
  • user_variables: Jinja2 variable substitutions applied to all string parameters.
  • prefix: A prefix prepended before the model’s generation.
  • output_prefix: A prefix prepended to the model’s output token stream (currently unsupported; must be None).
  • images: Images to include in the prompt.
Attributes:
  • requirements: The resolved list of requirement instances attached to this instruction.
Methods:

FUNC parts

parts(self)
Returns all of the constituent parts of an Instruction.

FUNC format_for_llm

format_for_llm(self) -> TemplateRepresentation
Format this instruction for the language model. Returns:
  • A template representation containing the
  • description, requirements, in-context examples, grounding context,
  • and optional prefix/repair fields.

FUNC apply_user_dict_from_jinja

apply_user_dict_from_jinja(user_dict: dict[str, str], s: str) -> str
Render a Jinja2 template string using the provided variable dictionary. Args:
  • user_dict: Mapping of Jinja2 variable names to their string replacement values.
  • s: A string treated as a Jinja2 template to be rendered.
Returns:
  • The rendered string with all Jinja2 placeholders substituted.

FUNC requirements

requirements(self) -> list[Requirement]
Returns a list of Requirement instances.

FUNC copy_and_repair

copy_and_repair(self, repair_string: str) -> Instruction
Create a deep copy of this instruction with the repair string set. Args:
  • repair_string: The repair feedback string to attach, typically describing which requirements failed and why.
Returns:
  • A new Instruction identical to this one but with
  • _repair_string set to repair_string.