@@ -178,10 +178,30 @@ export class Decorators extends APIResource {
178
178
if ( record . output ) payload . output = record . output ;
179
179
180
180
// Validate and include instructions if required by config
181
- if ( config . instruction_adherence && ! record . instructions ) {
182
- throw new Error (
183
- "When instruction_adherence is specified in the config, 'instructions' must be present in the dataset"
184
- ) ;
181
+ if ( config . instruction_adherence ) {
182
+ if ( ! record . instructions ) {
183
+ throw new Error (
184
+ "When instruction_adherence is specified in the config, 'instructions' must be present in the dataset"
185
+ ) ;
186
+ }
187
+
188
+ if ( Array . isArray ( record . instructions ) ) {
189
+ payload . instructions = record . instructions ;
190
+ } else if ( typeof record . instructions === "string" ) {
191
+ try {
192
+ const parsed = JSON . parse ( record . instructions ) ;
193
+ payload . instructions = Array . isArray ( parsed )
194
+ ? parsed
195
+ : [ record . instructions ] ;
196
+ } catch {
197
+ // If it's not valid JSON, treat the string as a single instruction
198
+ payload . instructions = [ record . instructions ] ;
199
+ }
200
+ } else {
201
+ throw new Error (
202
+ "'instructions' must be a string or array of strings"
203
+ ) ;
204
+ }
185
205
}
186
206
187
207
// Validate and include task definition if required by config
@@ -191,10 +211,6 @@ export class Decorators extends APIResource {
191
211
) ;
192
212
}
193
213
194
- if ( record . instructions && config . instruction_adherence ) {
195
- payload . instructions = record . instructions || "" ;
196
- }
197
-
198
214
if ( record . task_definition && config . retrieval_relevance ) {
199
215
payload . task_definition = record . task_definition || "" ;
200
216
}
0 commit comments