Conversation
Fixes 567-labs#1932 Move pre-commit and ty from production dependencies to dev optional-dependencies. These are development tools that should not be installed for production use. Changes: - Remove pre-commit>=4.3.0 from [project.dependencies] - Remove ty>=0.0.1a23 from [project.dependencies] - Add ty>=0.0.1a23 to [project.optional-dependencies.dev] (pre-commit was already present in dev)
Fixes 567-labs#1514 Add json_system_prompt parameter to handle_json_modes() allowing users to: - Customize the system prompt with {schema} placeholder - Set to empty string to skip prompt modification entirely - Default behavior unchanged (backward compatible) This enables use cases like roleplay where the 'genius expert' default breaks character consistency. Files: - instructor/providers/openai/utils.py - Core implementation - instructor/processing/response.py - Pass through parameter - tests/test_json_system_prompt.py - 8 comprehensive tests
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
instructor/providers/openai/utils.py
Outdated
| message = None | ||
| elif json_system_prompt is not None: | ||
| # Custom prompt provided - substitute {schema} placeholder | ||
| message = json_system_prompt.format(schema=json_schema) |
There was a problem hiding this comment.
Format string crashes on prompts with curly braces
Medium Severity
Using str.format() for placeholder substitution causes a KeyError if json_system_prompt contains curly braces other than {schema}. Users may reasonably want to include JSON examples in their prompt like "Return JSON like: {"id": 1} matching {schema}", which will crash. Literal braces require escaping as {{ and }}, but this limitation isn't documented. Consider using a safer substitution method like str.replace("{schema}", json_schema) instead.
Fixes Cursor Bugbot issue: str.format() crashes when prompts contain
curly braces like JSON examples (e.g., {"id": 1}). Using str.replace()
safely handles any curly braces in the custom prompt.
|
Thanks for the feedback, @jxnl
That makes sense — I was approaching this from a simple use case
(customizing or disabling the prompt), but I agree a V2 could benefit from
a more principled design.
While working on this, a few ideas came up:
-
*Template engine* — Support multiple placeholders like {schema},
{model_name}, {description}
-
*Prompt builders* — Composable sections (schema, instructions, examples)
with presets
-
*Mode-specific configs* — Different strategies per mode (JSON vs
JSON_SCHEMA vs MD_JSON)
I’d be happy to help implement whichever direction you choose for V2. Let
me know if you’d like me to iterate on this PR or close it in favor of a
more comprehensive solution.
…On Mon, 26 Jan 2026 at 20:26, Jason Liu ***@***.***> wrote:
*jxnl* left a comment (567-labs/instructor#2031)
<#2031 (comment)>
I'm working on a V2, and I'll try to think a little bit harder about how
we can parametrize the system prompt a little bit.
—
Reply to this email directly, view it on GitHub
<#2031 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BBEYB4AS6MOCPNRO2PN7K2D4IYTKPAVCNFSM6AAAAACS2WX6PGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQMBQGAYTMNJQHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
🔧 Fix for Ruff lint failure: Remove the unused imports in (Keep only the imports that are actually used in the test file.) |
Add
json_system_promptparameter for Mode.JSON allowing users to customizeor disable the default system prompt.
Type of Change
Related Issues
Fixes #1514
Changes Made
json_system_promptparameter tohandle_json_modes(){schema}placeholder for JSON schema injectionNote
Enables customizable system prompts for OpenAI JSON modes while preserving default behavior.
json_system_promptsupport inhandle_json_modesforMode.JSON,Mode.MD_JSON, andMode.JSON_SCHEMA; supports{schema}substitution and empty-string to disable system prompt changesresponse.pyto passjson_system_promptthrough mode handlersJSON_SCHEMAWritten by Cursor Bugbot for commit 2bfb3ca. Configure here.