- class PromptEnvelope(*, llm: LLMIntegration, db_schema: str, validators: Sequence[heimdallm.bifrosts.sql.validator.ConstraintValidator])
The purpose of the prompt envelope is to wrap the untrusted input in additional context for the LLM to produce the correct output. We do not do validation in the envelope, because it is impossible to prevent prompt injection.
While not necessary to subclass, you are recommended to do so if you want to customize the envelope.
db_schema (str) – The database schema of the database being queried. It is passed to the LLM so that the LLM knows how the tables and columns are connected.
validators (Sequence[heimdallm.bifrosts.sql.validator.ConstraintValidator]) – The validators to use to validate the output of the LLM. They aren’t used to validate here, but some of the validator’s properties are added to the envelope to help guide the LLM to produce the correct output.
- property params: dict
Returns a dictionary of additional parameters to be passed to the template. Override in a subclass for complete control over values that you want in the envelope.
The extra parameters to pass to the template.
- abstract template(env: Environment) Template
Returns the template to use for the envelope. Override in a subclass for complete customization.
- unwrap(untrusted_llm_output: str) str
Unpack the SQL query from the LLM output by finding it (hopefully) among the delimiters.
- wrap(untrusted_input: str) str