validateSafeOutputsSamples validates every `samples` entry on every enabled safe-output handler against the corresponding MCP tool's inputSchema. Sample sidecar fields (e.g. `patch`) are stripped before validation. Returns the first error encountered; iteration order is deterministic (sorted by stru
(config *SafeOutputsConfig)
| 103 | // the first error encountered; iteration order is deterministic (sorted by |
| 104 | // struct field name) so error messages are stable. |
| 105 | func validateSafeOutputsSamples(config *SafeOutputsConfig) error { |
| 106 | if config == nil { |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | fieldNames := sliceutil.SortedKeys(safeOutputFieldMapping) |
| 111 | samplesValidationLog.Printf("Validating safe-outputs samples across %d candidate fields", len(fieldNames)) |
| 112 | |
| 113 | for _, fieldName := range fieldNames { |
| 114 | toolName := safeOutputFieldMapping[fieldName] |
| 115 | base := extractBaseSafeOutputConfig(config, fieldName) |
| 116 | if base == nil || len(base.Samples) == 0 { |
| 117 | continue |
| 118 | } |
| 119 | samplesValidationLog.Printf("Validating %d sample(s) for field %q (tool %q)", len(base.Samples), fieldName, toolName) |
| 120 | if err := validateSamplesForTool(toolName, base.Samples); err != nil { |
| 121 | return err |
| 122 | } |
| 123 | } |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | // extractBaseSafeOutputConfig returns the embedded BaseSafeOutputConfig of the |
| 128 | // non-nil safe-output config at SafeOutputsConfig.<fieldName>, or nil if the |