MCPcopy Index your code
hub / github.com/simstudioai/sim / generateStructuredOutputInstructions

Function generateStructuredOutputInstructions

apps/sim/providers/utils.ts:382–437  ·  view source on GitHub ↗
(responseFormat: any)

Source from the content-addressed store, hash-verified

380}
381
382export function generateStructuredOutputInstructions(responseFormat: any): string {
383 if (!responseFormat) return ''
384
385 if (responseFormat.schema || (responseFormat.type === 'object' && responseFormat.properties)) {
386 return ''
387 }
388
389 if (!responseFormat.fields) return ''
390
391 function generateFieldStructure(field: any): string {
392 if (field.type === 'object' && field.properties) {
393 return `{
394 ${Object.entries(field.properties)
395 .map(([key, prop]: [string, any]) => `"${key}": ${prop.type === 'number' ? '0' : '"value"'}`)
396 .join(',\n ')}
397 }`
398 }
399 return field.type === 'string'
400 ? '"value"'
401 : field.type === 'number'
402 ? '0'
403 : field.type === 'boolean'
404 ? 'true/false'
405 : '[]'
406 }
407
408 const exampleFormat = responseFormat.fields
409 .map((field: any) => ` "${field.name}": ${generateFieldStructure(field)}`)
410 .join(',\n')
411
412 const fieldDescriptions = responseFormat.fields
413 .map((field: any) => {
414 let desc = `${field.name} (${field.type})`
415 if (field.description) desc += `: ${field.description}`
416 if (field.type === 'object' && field.properties) {
417 desc += '\nProperties:'
418 Object.entries(field.properties).forEach(([key, prop]: [string, any]) => {
419 desc += `\n - ${key} (${(prop as any).type}): ${(prop as any).description || ''}`
420 })
421 }
422 return desc
423 })
424 .join('\n')
425
426 return `
427Please provide your response in the following JSON format:
428{
429${exampleFormat}
430}
431
432Field descriptions:
433${fieldDescriptions}
434
435Your response MUST be valid JSON and include all the specified fields with their correct types.
436Each metric should be an object containing 'score' (number) and 'reasoning' (string).`
437}
438
439export function extractAndParseJSON(content: string): any {

Callers 2

executeProviderRequestFunction · 0.90
utils.test.tsFile · 0.90

Calls 2

generateFieldStructureFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected