Skip to content

Commit 4201b9a

Browse files
DevUI: Serialize workflow input as string to maintain conformance with OpenAI Responses format (#2021)
Co-authored-by: Victor Dibia <[email protected]>
1 parent 1aaf37d commit 4201b9a

File tree

5 files changed

+78
-39
lines changed

5 files changed

+78
-39
lines changed

dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Models/ResponseInput.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ internal sealed class ResponseInputJsonConverter : JsonConverter<ResponseInput>
182182
return messages is not null ? ResponseInput.FromMessages(messages) : null;
183183
}
184184

185-
throw new JsonException($"Unexpected token type for ResponseInput: {reader.TokenType}");
185+
throw new JsonException(
186+
"ResponseInput must be either a string or an array of messages. " +
187+
$"Objects are not supported. Received token type: {reader.TokenType}");
186188
}
187189

188190
/// <inheritdoc/>

dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIResponsesSerializationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ public void Deserialize_RefusalStreamingRequest_HasStream()
344344
Assert.NotNull(request.Input);
345345
}
346346

347+
[Fact]
348+
public void Deserialize_InvalidInputObject_ThrowsHelpfulException()
349+
{
350+
// Arrange
351+
const string Json = "{\"model\":\"gpt-4o-mini\",\"input\":{\"input\":\"testing!\"},\"stream\":true}";
352+
353+
// Act & Assert
354+
var exception = Assert.Throws<JsonException>(() =>
355+
JsonSerializer.Deserialize(Json, OpenAIHostingJsonContext.Default.CreateResponse));
356+
357+
Assert.Contains("ResponseInput must be either a string or an array of messages", exception.Message);
358+
Assert.Contains("Objects are not supported", exception.Message);
359+
}
360+
347361
[Fact]
348362
public void Deserialize_AllRequests_CanBeDeserialized()
349363
{

0 commit comments

Comments
 (0)