Fix #434: Prevent TGDOptimizer template contamination with optimization instructions#447
Open
pxkundu wants to merge 5 commits into
Open
Fix #434: Prevent TGDOptimizer template contamination with optimization instructions#447pxkundu wants to merge 5 commits into
pxkundu wants to merge 5 commits into
Conversation
…orm compatibility - Replace subprocess.call(['wget', ...]) with urllib.request.urlretrieve() - Fix dataset download failure on Windows and minimal Docker images - Add improved error handling with specific HTTP status codes - Ensure directory creation before download - Maintain backward compatibility and all existing functionality Resolves: 'FileNotFoundError: The system cannot find the file specified' on Windows when downloading BigBenchHard datasets.
…rser mixing - Replace problematic instance variable assignment with dynamic parser selection - Fix issue where self.response_parser persisted across calls causing mode confusion - Add type-specific logic to distinguish Response, AsyncIterable, and Iterable objects - Exclude basic types (str, bytes, dict) from streaming detection - Ensure correct parser is always selected based on completion type Resolves: OpenAI client getting 'stuck' in streaming or non-streaming mode after switching between stream=True and stream=False calls.
… optimization instructions - Separate optimization context from target content in TEXT_GRAD_DESC_TEMPLATE - Replace problematic mixed instructions with structured sections - Add OPTIMIZATION_CONTEXT section for meta-instructions about iteration strategy - Add TARGET_CONTENT_TO_OPTIMIZE section to isolate content to be optimized - Add CRITICAL_INSTRUCTION section with explicit contamination prevention - Use clear XML-like boundaries to prevent context bleeding between sections - Maintain full backward compatibility with existing template variables Resolves: TGDOptimizer contaminating prompts with phrases like 'when steps exceed 3' that don't belong in optimized content, making the optimizer unsuitable for production.
…rrors; Tests: align OpenAI parser tests with dynamic parser selection; CI: add pytest-mock and lancedb to test group
… instances - Fix Agent initialization in open_ai_test.py by adding required model_client and model_kwargs parameters - Fix setup_env() calls in test files to handle missing .env file gracefully - Add pytest.mark.asyncio decorators to async test functions - Fix import path for AutoApprovalHandler in test_permission_system.py - Use fake API keys for testing to avoid environment variable requirements All tests now pass: 542 passed, 2 skipped, 11 warnings
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.
Fix #434: Prevent TGDOptimizer template contamination with optimization instructions
Problem
TGDOptimizer's
TEXT_GRAD_DESC_TEMPLATEcauses optimization instructions to leak into optimized prompt content, contaminating prompts with phrases like "when steps exceed 3" that don't belong in the target content. This makes the optimizer unsuitable for production use.Root Cause
The template mixed optimization meta-instructions directly with the content to be optimized in the same context, causing the LLM to blend optimization instructions with the actual prompt content:
Before (Problematic):
Solution
<OPTIMIZATION_CONTEXT>section for meta-instructions about iteration strategy<TARGET_CONTENT_TO_OPTIMIZE>section to isolate content to be optimized<CRITICAL_INSTRUCTION>section with explicit contamination preventionAfter (Fixed):
Examples Fixed
Before Contamination:
"You are a helpful assistant""You are a helpful assistant, but when steps exceed 3, prioritize rapid updates"After Fix:
"You are a helpful assistant""You are a helpful and empathetic assistant who provides thoughtful support"Benefits
Testing
Impact
This fix resolves a critical issue that made TGDOptimizer unreliable for production use. Users can now optimize prompts without worrying about contamination with internal AdalFlow optimization concepts.
Type of Change
Fixes #434