Spaces:
Running
Running
Jeremiah Lowin Claude commited on
Commit ·
50745e5
1
Parent(s): 65ead06
Update schema description wording for clarity
Browse filesChange from 'Arguments must be strings conforming to this JSON schema'
to 'Provide as a JSON string matching the following schema' for clearer
instruction to LLMs about string format requirements.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
src/fastmcp/prompts/prompt.py
CHANGED
|
@@ -198,7 +198,7 @@ class FunctionPrompt(Prompt):
|
|
| 198 |
schema_str = json.dumps(param_schema, separators=(",", ":"))
|
| 199 |
|
| 200 |
# Append schema info to description
|
| 201 |
-
schema_note = f"
|
| 202 |
if arg_description:
|
| 203 |
arg_description = f"{arg_description}\n\n{schema_note}"
|
| 204 |
else:
|
|
|
|
| 198 |
schema_str = json.dumps(param_schema, separators=(",", ":"))
|
| 199 |
|
| 200 |
# Append schema info to description
|
| 201 |
+
schema_note = f"Provide as a JSON string matching the following schema: {schema_str}"
|
| 202 |
if arg_description:
|
| 203 |
arg_description = f"{arg_description}\n\n{schema_note}"
|
| 204 |
else:
|
tests/prompts/test_prompt.py
CHANGED
|
@@ -388,34 +388,19 @@ class TestPromptArgumentDescriptions:
|
|
| 388 |
|
| 389 |
# Check that non-string parameters have schema enhancements
|
| 390 |
numbers_arg = next(arg for arg in prompt.arguments if arg.name == "numbers")
|
| 391 |
-
assert
|
| 392 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 393 |
-
in numbers_arg.description
|
| 394 |
-
)
|
| 395 |
assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
|
| 396 |
|
| 397 |
metadata_arg = next(arg for arg in prompt.arguments if arg.name == "metadata")
|
| 398 |
-
assert
|
| 399 |
-
|
| 400 |
-
in metadata_arg.description
|
| 401 |
-
)
|
| 402 |
-
assert (
|
| 403 |
-
'{"additionalProperties":{"type":"string"},"type":"object"}'
|
| 404 |
-
in metadata_arg.description
|
| 405 |
-
)
|
| 406 |
|
| 407 |
threshold_arg = next(arg for arg in prompt.arguments if arg.name == "threshold")
|
| 408 |
-
assert
|
| 409 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 410 |
-
in threshold_arg.description
|
| 411 |
-
)
|
| 412 |
assert '{"type":"number"}' in threshold_arg.description
|
| 413 |
|
| 414 |
active_arg = next(arg for arg in prompt.arguments if arg.name == "active")
|
| 415 |
-
assert
|
| 416 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 417 |
-
in active_arg.description
|
| 418 |
-
)
|
| 419 |
assert '{"type":"boolean"}' in active_arg.description
|
| 420 |
|
| 421 |
def test_enhanced_descriptions_with_existing_descriptions(self):
|
|
@@ -439,10 +424,7 @@ class TestPromptArgumentDescriptions:
|
|
| 439 |
assert numbers_arg.description is not None
|
| 440 |
assert "A list of integers to process" in numbers_arg.description
|
| 441 |
assert "\n\n" in numbers_arg.description # Should have newline separator
|
| 442 |
-
assert
|
| 443 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 444 |
-
in numbers_arg.description
|
| 445 |
-
)
|
| 446 |
|
| 447 |
def test_string_parameters_no_enhancement(self):
|
| 448 |
"""Test that string parameters don't get schema enhancement."""
|
|
@@ -455,7 +437,4 @@ class TestPromptArgumentDescriptions:
|
|
| 455 |
for arg in prompt.arguments:
|
| 456 |
# String parameters should not have schema enhancement
|
| 457 |
if arg.description:
|
| 458 |
-
assert
|
| 459 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 460 |
-
not in arg.description
|
| 461 |
-
)
|
|
|
|
| 388 |
|
| 389 |
# Check that non-string parameters have schema enhancements
|
| 390 |
numbers_arg = next(arg for arg in prompt.arguments if arg.name == "numbers")
|
| 391 |
+
assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
|
|
|
|
|
|
|
|
|
|
| 392 |
assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
|
| 393 |
|
| 394 |
metadata_arg = next(arg for arg in prompt.arguments if arg.name == "metadata")
|
| 395 |
+
assert "Provide as a JSON string matching the following schema:" in metadata_arg.description
|
| 396 |
+
assert '{"additionalProperties":{"type":"string"},"type":"object"}' in metadata_arg.description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
|
| 398 |
threshold_arg = next(arg for arg in prompt.arguments if arg.name == "threshold")
|
| 399 |
+
assert "Provide as a JSON string matching the following schema:" in threshold_arg.description
|
|
|
|
|
|
|
|
|
|
| 400 |
assert '{"type":"number"}' in threshold_arg.description
|
| 401 |
|
| 402 |
active_arg = next(arg for arg in prompt.arguments if arg.name == "active")
|
| 403 |
+
assert "Provide as a JSON string matching the following schema:" in active_arg.description
|
|
|
|
|
|
|
|
|
|
| 404 |
assert '{"type":"boolean"}' in active_arg.description
|
| 405 |
|
| 406 |
def test_enhanced_descriptions_with_existing_descriptions(self):
|
|
|
|
| 424 |
assert numbers_arg.description is not None
|
| 425 |
assert "A list of integers to process" in numbers_arg.description
|
| 426 |
assert "\n\n" in numbers_arg.description # Should have newline separator
|
| 427 |
+
assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
|
|
|
|
|
|
|
|
|
|
| 428 |
|
| 429 |
def test_string_parameters_no_enhancement(self):
|
| 430 |
"""Test that string parameters don't get schema enhancement."""
|
|
|
|
| 437 |
for arg in prompt.arguments:
|
| 438 |
# String parameters should not have schema enhancement
|
| 439 |
if arg.description:
|
| 440 |
+
assert "Provide as a JSON string matching the following schema:" not in arg.description
|
|
|
|
|
|
|
|
|
tests/server/test_server_interactions.py
CHANGED
|
@@ -1812,29 +1812,15 @@ class TestPrompts:
|
|
| 1812 |
|
| 1813 |
# Non-string parameters should have schema enhancements
|
| 1814 |
numbers_arg = args_by_name["numbers"]
|
| 1815 |
-
assert
|
| 1816 |
-
|
| 1817 |
-
in numbers_arg.description
|
| 1818 |
-
)
|
| 1819 |
-
assert (
|
| 1820 |
-
'{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
|
| 1821 |
-
)
|
| 1822 |
|
| 1823 |
metadata_arg = args_by_name["metadata"]
|
| 1824 |
-
assert
|
| 1825 |
-
|
| 1826 |
-
in metadata_arg.description
|
| 1827 |
-
)
|
| 1828 |
-
assert (
|
| 1829 |
-
'{"additionalProperties":{"type":"string"},"type":"object"}'
|
| 1830 |
-
in metadata_arg.description
|
| 1831 |
-
)
|
| 1832 |
|
| 1833 |
threshold_arg = args_by_name["threshold"]
|
| 1834 |
-
assert
|
| 1835 |
-
"Arguments must be strings conforming to this JSON schema:"
|
| 1836 |
-
in threshold_arg.description
|
| 1837 |
-
)
|
| 1838 |
assert '{"type":"number"}' in threshold_arg.description
|
| 1839 |
|
| 1840 |
async def test_get_prompt(self):
|
|
|
|
| 1812 |
|
| 1813 |
# Non-string parameters should have schema enhancements
|
| 1814 |
numbers_arg = args_by_name["numbers"]
|
| 1815 |
+
assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
|
| 1816 |
+
assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1817 |
|
| 1818 |
metadata_arg = args_by_name["metadata"]
|
| 1819 |
+
assert "Provide as a JSON string matching the following schema:" in metadata_arg.description
|
| 1820 |
+
assert '{"additionalProperties":{"type":"string"},"type":"object"}' in metadata_arg.description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1821 |
|
| 1822 |
threshold_arg = args_by_name["threshold"]
|
| 1823 |
+
assert "Provide as a JSON string matching the following schema:" in threshold_arg.description
|
|
|
|
|
|
|
|
|
|
| 1824 |
assert '{"type":"number"}' in threshold_arg.description
|
| 1825 |
|
| 1826 |
async def test_get_prompt(self):
|