mellea.stdlib.requirement
mellea.stdlib.requirement.default_output_to_bool(x: CBlock | str)
True
.
Checks if the output is exactly equal to “yes” or “y” (case-insensitive). If not, it will also
check if any of the words in the output are “yes” (case-insensitive).
mellea.stdlib.requirement.reqify(r: str | Requirement)
mellea.stdlib.requirement.req(*args, **kwargs)
mellea.stdlib.requirement.check(*args, **kwargs)
mellea.stdlib.requirement.simple_validate(fn: Callable[[str], bool])
Requirement("Answer 'yes' or 'no'", simple_validate(lambda x: x == 'yes' or x == 'no')
Validation functions operate over Context
. Often you do not care about the entire context, and just want to consider the most recent output from the model.
Important notes:
Formatter.parse
call or an OutputProcessor). This validation logic will interpret the most recent output as a string, regardless of whether it has a more complex parsed representation.class mellea.stdlib.requirement.Requirement(description: str | None = None, validation_fn: Callable[[Context], Any] | None = None, output_to_bool: Callable[[CBlock | str], bool] | None = default_output_to_bool, check_only: bool = False)
constraint
LoRA when available). However, you can also provide a validate
function with arbitrary behavior.
description
: A natural-language description of the requirement. This will sometimes be included in
Instruction prompts; if you do not want the requirement to be included in the prompt to avoid [Purple Elephant Effects](https
: //$/llm-requirement-engineering-and-purple-elephants/) use check_only=True.validation_fn
: If provided, this function will be executed instead of using LLM-as-a-Judge. The bool()
for the function’s output defines whether the requirement passes.output_to_bool
: An output_to_bool
may be provided so that the library can translate the LLM-as-a-judge or ALora output into a boolean value. If none is provided, we will look for ‘yes’ (case-insensitive) in the LLMaJ output.check_only
: If set, then Instruction
will not include this requirement in its prompt.mellea.stdlib.requirement.Requirement.validate(backend: Backend, ctx: Context, format: type[BaseModelSubclass] | None = None, model_options: dict | None = None, generate_logs: list[GenerateLog] | None = None)
mellea.stdlib.requirement.Requirement.parts()
mellea.stdlib.requirement.Requirement.format_for_llm()
class mellea.stdlib.requirement.LLMaJRequirement()
class mellea.stdlib.requirement.ALoraRequirement(description: str, alora: Alora | None = None)
mellea
will fall back to LLMaJ. But that is the only case where LLMaJ will be used.
description
: See Requirement.__init__
alora
: if None, the ALora with name “constraint” will be used.