Prompt Envelopeο
- 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.
- Parameters:
llm (LLMIntegration) β The LLM integration being sent the human input. This can be used to tweak the
wrap()
andunwrap()
methods to account for quirks of the specific LLM.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.
- Returns:
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.
- Parameters:
env (Environment) β The environment to use to load the template.
- Returns:
The template to use for the envelope.
- Return type:
- 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 ο
Performs the wrapping of the untrusted input with the envelope. Not intended to be overridden, but not foribben either. Consider overriding the
template()
andparams()
properties first instead.