preparePrompt method

String preparePrompt({
  1. required String originalPrompt,
  2. required StructuredOutputConfig config,
})

Prepare prompt with structured output instructions

Implementation

String preparePrompt({
  required String originalPrompt,
  required StructuredOutputConfig config,
}) {
  if (!config.includeSchemaInPrompt) {
    return originalPrompt;
  }

  final instructions = '''
CRITICAL INSTRUCTION: You MUST respond with ONLY a valid JSON object. No other text is allowed.

JSON Schema:
${config.schema}

RULES:
1. Start your response with { and end with }
2. Include NO text before the opening {
3. Include NO text after the closing }
4. Follow the schema exactly
5. All required fields must be present
6. Use exact field names from the schema
7. Ensure proper JSON syntax (quotes, commas, etc.)

IMPORTANT: Your entire response must be valid JSON that can be parsed. Do not include any explanations, comments, or additional text.
''';

  return '''
System: You are a JSON generator. You must output only valid JSON.

$originalPrompt

$instructions

Remember: Output ONLY the JSON object, nothing else.
''';
}