openai / openai/openai-java

Structured outputs `Map` handling has confusing error message and isn't well documented

Open
#485 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api documentation
Dominant language
Kotlin
Stars
1.5k
Forks
264
Avg merge
9h 46m
Merged PRs (30d)
96

Description

I found that when you pass an object with a map to StructuredChatCompletionCreateParams the API returns a 400 response Caused by: com.openai.errors.BadRequestException: 400: Invalid schema for response_format 'json-schema-from-TestMap': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Extra required key 'coolMap' supplied.

Object
  private static class TestMap {
    public Map<String, Integer> coolMap;
  }
Full stack
Caused by: com.openai.errors.BadRequestException: 400: Invalid schema for response_format 'json-schema-from-TestMap': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Extra required key 'coolMap' supplied.
	at com.openai.errors.BadRequestException$Builder.build(BadRequestException.kt:88) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.core.handlers.ErrorHandler$withErrorHandler$1.handle(ErrorHandler.kt:48) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.services.blocking.chat.ChatCompletionServiceImpl$WithRawResponseImpl$create$1.invoke(ChatCompletionServiceImpl.kt:122) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.services.blocking.chat.ChatCompletionServiceImpl$WithRawResponseImpl$create$1.invoke(ChatCompletionServiceImpl.kt:120) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.core.http.HttpResponseForKt$parseable$1$parsed$2.invoke(HttpResponseFor.kt:14) ~[openai-java-core-2.0.0.jar:2.0.0]
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
	at com.openai.core.http.HttpResponseForKt$parseable$1.getParsed(HttpResponseFor.kt:14) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.core.http.HttpResponseForKt$parseable$1.parse(HttpResponseFor.kt:16) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.services.blocking.chat.ChatCompletionServiceImpl.create(ChatCompletionServiceImpl.kt:56) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.services.blocking.chat.ChatCompletionService.create(ChatCompletionService.kt:80) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.openai.services.blocking.chat.ChatCompletionService.create(ChatCompletionService.kt:67) ~[openai-java-core-2.0.0.jar:2.0.0]
	at com.zeroClick.core.chatgpt.ChatGPT.run(ChatGPT.java:108) ~[classes/:na]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at StructuredChatCompletionCreateParams and reproduce the 400 response with the TestMap example containing coolMap. Trace the structured-output schema generation and related documentation, then add regression coverage and clarify the supported Map behavior and error message.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.