From c3f5d492e787badec8212a0c69db8e51de6bd67e Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Tue, 17 Sep 2024 09:50:51 -0700 Subject: [PATCH] Improve JsonSchemaRule template (#1175) --- docs/griptape-framework/structures/rulesets.md | 2 +- griptape/templates/rules/json_schema.j2 | 3 ++- tests/unit/rules/test_json_schema_rule.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/griptape-framework/structures/rulesets.md b/docs/griptape-framework/structures/rulesets.md index a0773856f..12f14a96e 100644 --- a/docs/griptape-framework/structures/rulesets.md +++ b/docs/griptape-framework/structures/rulesets.md @@ -30,7 +30,7 @@ A [Ruleset](../../reference/griptape/rules/ruleset.md) can be used to define [Ru This is particularly useful when you need the LLM to return well-formed data, such as JSON objects, with specific fields and data types. !!! warning - `JsonSchemaRule` may break [ToolkitTask](../structures/tasks.md#toolkittask) which relies on a specific [output token](https://github.com/griptape-ai/griptape/blob/e6a04c7b88cf9fa5d6bcf4c833ffebfab89a3258/griptape/tasks/toolkit_task.py#L28). + `JsonSchemaRule` may break [ToolkitTask](../structures/tasks.md#toolkit) which relies on a specific [output token](https://github.com/griptape-ai/griptape/blob/e6a04c7b88cf9fa5d6bcf4c833ffebfab89a3258/griptape/tasks/toolkit_task.py#L28). ```python diff --git a/griptape/templates/rules/json_schema.j2 b/griptape/templates/rules/json_schema.j2 index 9a351c1cd..837f9d67c 100644 --- a/griptape/templates/rules/json_schema.j2 +++ b/griptape/templates/rules/json_schema.j2 @@ -1 +1,2 @@ -You must respond with a JSON object that successfully validates against the following schema: {{json_schema}} +Output valid JSON that matches this schema: {{ json_schema }} +No markdown, code snippets, code blocks, or backticks. diff --git a/tests/unit/rules/test_json_schema_rule.py b/tests/unit/rules/test_json_schema_rule.py index a1a4f2361..f3619b66b 100644 --- a/tests/unit/rules/test_json_schema_rule.py +++ b/tests/unit/rules/test_json_schema_rule.py @@ -23,7 +23,7 @@ def test_to_text(self): rule = JsonSchemaRule(json_schema) assert ( rule.to_text() - == f"You must respond with a JSON object that successfully validates against the following schema: {json.dumps(json_schema)}" + == f"Output valid JSON that matches this schema: {json.dumps(json_schema)}\nNo markdown, code snippets, code blocks, or backticks." ) def test___str__(self):