Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input validation #483

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
raise on msg_history/prompt validation mismatch
irgolic committed Dec 4, 2023
commit 6a3ddaa43fa16e3f0b63a9b24cbe7232a0360438
14 changes: 13 additions & 1 deletion guardrails/run.py
Original file line number Diff line number Diff line change
@@ -198,6 +198,7 @@ def step(
prompt_params: Dict,
prompt_schema: Optional[StringSchema],
instructions_schema: Optional[StringSchema],
msg_history_schema: Optional[StringSchema],
output_schema: Schema,
output: Optional[str] = None,
):
@@ -212,7 +213,7 @@ def step(
prompt_params=prompt_params,
prompt_schema=prompt_schema,
instructions_schema=instructions_schema,
msg_history_schema=self.msg_history_schema,
msg_history_schema=msg_history_schema,
output_schema=output_schema,
):
# Prepare: run pre-processing, and input validation.
@@ -231,6 +232,7 @@ def step(
api,
prompt_schema,
instructions_schema,
msg_history_schema,
output_schema,
)

@@ -305,6 +307,11 @@ def prepare(
prompt_params = {}

if msg_history:
if prompt_schema is not None or instructions_schema is not None:
raise ValueError(
"Prompt and instructions validation are "
"not supported when using message history."
)
msg_history = copy.deepcopy(msg_history)
# Format any variables in the message history with the prompt params.
for msg in msg_history:
@@ -325,6 +332,11 @@ def prepare(
)
msg_history = validated_msg_history
elif prompt is not None:
if msg_history_schema is not None:
raise ValueError(
"Message history validation is "
"not supported when using prompt/instructions."
)
if isinstance(prompt, str):
prompt = Prompt(prompt)