fix(config): add !rawfile tag to bypass YAML-sniffing on prompt includes - #529
Open
Amir Fathi (AmirF194) wants to merge 1 commit into
Open
Amir Fathi (AmirF194) wants to merge 1 commit into
Amir Fathi (AmirF194) wants to merge 1 commit into
Conversation
!file parses every included file's content as YAML and returns a dict/list whenever the sub-parse succeeds structurally. A Markdown prompt whose prose happens to parse as YAML (a line ending in ':' followed by a '- ' bullet list) then fails prompt/system_prompt validation, and an unrelated prose edit can flip a working file across that boundary. Add !rawfile, which always returns the file's content verbatim. Extract the shared file-reading and cycle-detection logic into _read_included_file so both tags use it; !rawfile skips the YAML sub-parse and never recurses. Fixes microsoft#528
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the YAML-sniffing trap you described: added a
!rawfiletag (your suggested direction 1) that always returns a file's content verbatim, so a prompt file's type can't flip depending on whether its prose happens to parse as YAML.construct_file_tag's file-reading and cycle-detection logic is now shared through a new_read_included_filehelper, used by both!fileand!rawfile.!rawfileskips the YAML sub-parse entirely, so it never recurses and doesn't need the nested-include bookkeeping!filehas.Documented it in
workflow-syntax.md, including the "an unrelated prose edit flips it" trap, and updated the Jinja-includes note since a!rawfile-loaded prompt gets the same include search root as!file(it keys offisinstance(x, FileString), not which tag produced it).Didn't touch direction 2 (a targeted error message on the existing
!fileheuristic).!rawfileis the actual escape hatch, so it seemed like the more useful half to ship first, and it doesn't preclude adding the error message later.Added tests for both sides: your exact repro (a line ending in
:followed by a bulleted list) still trips!fileas before, and the same file loaded through!rawfilestays a string.pytest tests/test_config/passes on the branch (1371 passed, 3 skipped, none related to this).ruff check/formatandty checkare clean on the changed file.Fixes #528