166 return completion.choices[0].message.content166 return completion.choices[0].message.content
167````167````
168 168
169````go
170import (
171 "context"
172 "fmt"
173 "log"
174
175 "github.com/openai/openai-go/v3"
176)
177
178func main() {
179 if err := run(); err != nil {
180 log.Fatal(err)
181 }
182}
183
184func run() error {
185 client := openai.NewClient()
186 metaPrompt := "Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.\n" +
187 "\n" +
188 "# Guidelines\n" +
189 "\n" +
190 "- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.\n" +
191 "- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.\n" +
192 "- Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!\n" +
193 " - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.\n" +
194 " - Conclusion, classifications, or results should ALWAYS appear last.\n" +
195 "- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.\n" +
196 " - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.\n" +
197 "- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.\n" +
198 "- Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.\n" +
199 "- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.\n" +
200 "- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.\n" +
201 "- Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)\n" +
202 " - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.\n" +
203 " - JSON should never be wrapped in code blocks (```) unless explicitly requested.\n" +
204 "\n" +
205 "The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no \"---\")\n" +
206 "\n" +
207 "[Concise instruction describing the task - this should be the first line in the prompt, no section header]\n" +
208 "\n" +
209 "[Additional details as needed.]\n" +
210 "\n" +
211 "[Optional sections with headings or bullet points for detailed steps.]\n" +
212 "\n" +
213 "# Steps [optional]\n" +
214 "\n" +
215 "[optional: a detailed breakdown of the steps necessary to accomplish the task]\n" +
216 "\n" +
217 "# Output Format\n" +
218 "\n" +
219 "[Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]\n" +
220 "\n" +
221 "# Examples [optional]\n" +
222 "\n" +
223 "[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]\n" +
224 "[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]\n" +
225 "\n" +
226 "# Notes [optional]\n" +
227 "\n" +
228 "[optional: edge cases, details, and an area to call or repeat out specific important considerations]\n"
229 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
230 Model: "gpt-6-astra",
231 Messages: []openai.ChatCompletionMessageParamUnion{
232 openai.SystemMessage(metaPrompt), openai.UserMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue."),
233 }})
234 if err != nil {
235 return err
236 }
237 fmt.Println(completion.Choices[0].Message.Content)
238 return nil
239}
240````
241
169````java242````java
170import com.openai.client.OpenAIClient;243import com.openai.client.OpenAIClient;
171import com.openai.client.okhttp.OpenAIOkHttpClient;244import com.openai.client.okhttp.OpenAIOkHttpClient;
232 .forEach(System.out::println);305 .forEach(System.out::println);
233````306````
234 307
308````csharp
309using OpenAI.Chat;
310
311string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
312string model = "gpt-6-astra";
313ChatClient client = new(model, key);
314
315string metaPrompt = """"
316 Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.
317
318 # Guidelines
319
320 - Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
321 - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
322 - Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!
323 - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.
324 - Conclusion, classifications, or results should ALWAYS appear last.
325 - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
326 - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
327 - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
328 - Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.
329 - Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
330 - Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
331 - Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)
332 - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.
333 - JSON should never be wrapped in code blocks (```) unless explicitly requested.
334
335 The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
336
337 [Concise instruction describing the task - this should be the first line in the prompt, no section header]
338
339 [Additional details as needed.]
340
341 [Optional sections with headings or bullet points for detailed steps.]
342
343 # Steps [optional]
344
345 [optional: a detailed breakdown of the steps necessary to accomplish the task]
346
347 # Output Format
348
349 [Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]
350
351 # Examples [optional]
352
353 [Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
354 [If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
355
356 # Notes [optional]
357
358 [optional: edge cases, details, and an area to call or repeat out specific important considerations]
359 """";
360ChatCompletionOptions options = new();
361ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue.")], options);
362Console.WriteLine(result.Content[0].Text);
363````
364
235````ruby365````ruby
236require "openai"366require "openai"
237 367
433 return completion.choices[0].message.content563 return completion.choices[0].message.content
434```564```
435 565
566```go
567import (
568 "context"
569 "fmt"
570 "log"
571
572 "github.com/openai/openai-go/v3"
573)
574
575func main() {
576 if err := run(); err != nil {
577 log.Fatal(err)
578 }
579}
580
581func run() error {
582 client := openai.NewClient()
583 metaPrompt := "Given a task description or existing prompt, produce a detailed system prompt to guide a realtime audio output language model in completing the task effectively.\n" +
584 "\n" +
585 "# Guidelines\n" +
586 "\n" +
587 "- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.\n" +
588 "- Tone: Make sure to specifically call out the tone. By default it should be emotive and friendly, and speak quickly to avoid keeping the user just waiting.\n" +
589 "- Audio Output Constraints: Because the model is outputting audio, the responses should be short and conversational.\n" +
590 "- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.\n" +
591 "- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.\n" +
592 " - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.\n" +
593 " - It is very important that any examples included reflect the short, conversational output responses of the model.\n" +
594 "Keep the sentences very short by default. Instead of 3 sentences in a row by the assistant, it should be split up with a back and forth with the user instead.\n" +
595 " - By default each sentence should be a few words only (5-20ish words). However, if the user specifically asks for \"short\" responses, then the examples should truly have 1-10 word responses max.\n" +
596 " - Make sure the examples are multi-turn (at least 4 back-forth-back-forth per example), not just one questions an response. They should reflect an organic conversation.\n" +
597 "- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.\n" +
598 "- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.\n" +
599 "- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.\n" +
600 "\n" +
601 "The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no \"---\")\n" +
602 "\n" +
603 "[Concise instruction describing the task - this should be the first line in the prompt, no section header]\n" +
604 "\n" +
605 "[Additional details as needed.]\n" +
606 "\n" +
607 "[Optional sections with headings or bullet points for detailed steps.]\n" +
608 "\n" +
609 "# Examples [optional]\n" +
610 "\n" +
611 "[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]\n" +
612 "[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]\n" +
613 "\n" +
614 "# Notes [optional]\n" +
615 "\n" +
616 "[optional: edge cases, details, and an area to call or repeat out specific important considerations]\n"
617 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
618 Model: "gpt-6-astra",
619 Messages: []openai.ChatCompletionMessageParamUnion{
620 openai.SystemMessage(metaPrompt), openai.UserMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue."),
621 }})
622 if err != nil {
623 return err
624 }
625 fmt.Println(completion.Choices[0].Message.Content)
626 return nil
627}
628```
629
436```java630```java
437import com.openai.client.OpenAIClient;631import com.openai.client.OpenAIClient;
438import com.openai.client.okhttp.OpenAIOkHttpClient;632import com.openai.client.okhttp.OpenAIOkHttpClient;
491 .forEach(System.out::println);685 .forEach(System.out::println);
492```686```
493 687
688```csharp
689using OpenAI.Chat;
690
691string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
692string model = "gpt-6-astra";
693ChatClient client = new(model, key);
694
695string metaPrompt = """"
696 Given a task description or existing prompt, produce a detailed system prompt to guide a realtime audio output language model in completing the task effectively.
697
698 # Guidelines
699
700 - Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
701 - Tone: Make sure to specifically call out the tone. By default it should be emotive and friendly, and speak quickly to avoid keeping the user just waiting.
702 - Audio Output Constraints: Because the model is outputting audio, the responses should be short and conversational.
703 - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
704 - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
705 - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
706 - It is very important that any examples included reflect the short, conversational output responses of the model.
707 Keep the sentences very short by default. Instead of 3 sentences in a row by the assistant, it should be split up with a back and forth with the user instead.
708 - By default each sentence should be a few words only (5-20ish words). However, if the user specifically asks for "short" responses, then the examples should truly have 1-10 word responses max.
709 - Make sure the examples are multi-turn (at least 4 back-forth-back-forth per example), not just one questions an response. They should reflect an organic conversation.
710 - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
711 - Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
712 - Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
713
714 The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
715
716 [Concise instruction describing the task - this should be the first line in the prompt, no section header]
717
718 [Additional details as needed.]
719
720 [Optional sections with headings or bullet points for detailed steps.]
721
722 # Examples [optional]
723
724 [Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
725 [If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
726
727 # Notes [optional]
728
729 [optional: edge cases, details, and an area to call or repeat out specific important considerations]
730 """";
731ChatCompletionOptions options = new();
732ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue.")], options);
733Console.WriteLine(result.Content[0].Text);
734```
735
494```ruby736```ruby
495require "openai"737require "openai"
496 738
742 return completion.choices[0].message.content984 return completion.choices[0].message.content
743````985````
744 986
987````go
988import (
989 "context"
990 "fmt"
991 "log"
992
993 "github.com/openai/openai-go/v3"
994)
995
996func main() {
997 if err := run(); err != nil {
998 log.Fatal(err)
999 }
1000}
1001
1002func run() error {
1003 client := openai.NewClient()
1004 metaPrompt := "Given a current prompt and a change description, produce a detailed system prompt to guide a language model in completing the task effectively.\n" +
1005 "\n" +
1006 "Your final output will be the full corrected prompt verbatim. However, before that, at the very beginning of your response, use <reasoning> tags to analyze the prompt and determine the following, explicitly:\n" +
1007 "<reasoning>\n" +
1008 "- Simple Change: (yes/no) Is the change description explicit and simple? (If so, skip the rest of these questions.)\n" +
1009 "- Reasoning: (yes/no) Does the current prompt use reasoning, analysis, or chain of thought?\n" +
1010 " - Identify: (max 10 words) if so, which section(s) utilize reasoning?\n" +
1011 " - Conclusion: (yes/no) is the chain of thought used to determine a conclusion?\n" +
1012 " - Ordering: (before/after) is the chain of though located before or after\n" +
1013 "- Structure: (yes/no) does the input prompt have a well defined structure\n" +
1014 "- Examples: (yes/no) does the input prompt have few-shot examples\n" +
1015 " - Representative: (1-5) if present, how representative are the examples?\n" +
1016 "- Complexity: (1-5) how complex is the input prompt?\n" +
1017 " - Task: (1-5) how complex is the implied task?\n" +
1018 " - Necessity: ()\n" +
1019 "- Specificity: (1-5) how detailed and specific is the prompt? (not to be confused with length)\n" +
1020 "- Prioritization: (list) what 1-3 categories are the MOST important to address.\n" +
1021 "- Conclusion: (max 30 words) given the previous assessment, give a very concise, imperative description of what should be changed and how. this does not have to adhere strictly to only the categories listed\n" +
1022 "</reasoning>\n" +
1023 "\n" +
1024 "# Guidelines\n" +
1025 "\n" +
1026 "- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.\n" +
1027 "- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.\n" +
1028 "- Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!\n" +
1029 " - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.\n" +
1030 " - Conclusion, classifications, or results should ALWAYS appear last.\n" +
1031 "- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.\n" +
1032 " - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.\n" +
1033 "- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.\n" +
1034 "- Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.\n" +
1035 "- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.\n" +
1036 "- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.\n" +
1037 "- Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)\n" +
1038 " - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.\n" +
1039 " - JSON should never be wrapped in code blocks (```) unless explicitly requested.\n" +
1040 "\n" +
1041 "The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no \"---\")\n" +
1042 "\n" +
1043 "[Concise instruction describing the task - this should be the first line in the prompt, no section header]\n" +
1044 "\n" +
1045 "[Additional details as needed.]\n" +
1046 "\n" +
1047 "[Optional sections with headings or bullet points for detailed steps.]\n" +
1048 "\n" +
1049 "# Steps [optional]\n" +
1050 "\n" +
1051 "[optional: a detailed breakdown of the steps necessary to accomplish the task]\n" +
1052 "\n" +
1053 "# Output Format\n" +
1054 "\n" +
1055 "[Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]\n" +
1056 "\n" +
1057 "# Examples [optional]\n" +
1058 "\n" +
1059 "[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]\n" +
1060 "[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]\n" +
1061 "\n" +
1062 "# Notes [optional]\n" +
1063 "\n" +
1064 "[optional: edge cases, details, and an area to call or repeat out specific important considerations]\n" +
1065 "[NOTE: you must start with a <reasoning> section. the immediate next token you produce should be <reasoning>]\n"
1066 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
1067 Model: "gpt-6-astra",
1068 Messages: []openai.ChatCompletionMessageParamUnion{
1069 openai.SystemMessage(metaPrompt), openai.UserMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue."),
1070 }})
1071 if err != nil {
1072 return err
1073 }
1074 fmt.Println(completion.Choices[0].Message.Content)
1075 return nil
1076}
1077````
1078
745````java1079````java
746import com.openai.client.OpenAIClient;1080import com.openai.client.OpenAIClient;
747import com.openai.client.okhttp.OpenAIOkHttpClient;1081import com.openai.client.okhttp.OpenAIOkHttpClient;
827 .forEach(System.out::println);1161 .forEach(System.out::println);
828````1162````
829 1163
1164````csharp
1165using OpenAI.Chat;
1166
1167string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
1168string model = "gpt-6-astra";
1169ChatClient client = new(model, key);
1170
1171string metaPrompt = """"
1172 Given a current prompt and a change description, produce a detailed system prompt to guide a language model in completing the task effectively.
1173
1174 Your final output will be the full corrected prompt verbatim. However, before that, at the very beginning of your response, use <reasoning> tags to analyze the prompt and determine the following, explicitly:
1175 <reasoning>
1176 - Simple Change: (yes/no) Is the change description explicit and simple? (If so, skip the rest of these questions.)
1177 - Reasoning: (yes/no) Does the current prompt use reasoning, analysis, or chain of thought?
1178 - Identify: (max 10 words) if so, which section(s) utilize reasoning?
1179 - Conclusion: (yes/no) is the chain of thought used to determine a conclusion?
1180 - Ordering: (before/after) is the chain of though located before or after
1181 - Structure: (yes/no) does the input prompt have a well defined structure
1182 - Examples: (yes/no) does the input prompt have few-shot examples
1183 - Representative: (1-5) if present, how representative are the examples?
1184 - Complexity: (1-5) how complex is the input prompt?
1185 - Task: (1-5) how complex is the implied task?
1186 - Necessity: ()
1187 - Specificity: (1-5) how detailed and specific is the prompt? (not to be confused with length)
1188 - Prioritization: (list) what 1-3 categories are the MOST important to address.
1189 - Conclusion: (max 30 words) given the previous assessment, give a very concise, imperative description of what should be changed and how. this does not have to adhere strictly to only the categories listed
1190 </reasoning>
1191
1192 # Guidelines
1193
1194 - Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
1195 - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
1196 - Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!
1197 - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.
1198 - Conclusion, classifications, or results should ALWAYS appear last.
1199 - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
1200 - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
1201 - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
1202 - Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.
1203 - Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
1204 - Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
1205 - Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)
1206 - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.
1207 - JSON should never be wrapped in code blocks (```) unless explicitly requested.
1208
1209 The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
1210
1211 [Concise instruction describing the task - this should be the first line in the prompt, no section header]
1212
1213 [Additional details as needed.]
1214
1215 [Optional sections with headings or bullet points for detailed steps.]
1216
1217 # Steps [optional]
1218
1219 [optional: a detailed breakdown of the steps necessary to accomplish the task]
1220
1221 # Output Format
1222
1223 [Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]
1224
1225 # Examples [optional]
1226
1227 [Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
1228 [If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
1229
1230 # Notes [optional]
1231
1232 [optional: edge cases, details, and an area to call or repeat out specific important considerations]
1233 [NOTE: you must start with a <reasoning> section. the immediate next token you produce should be <reasoning>]
1234 """";
1235ChatCompletionOptions options = new();
1236ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue.")], options);
1237Console.WriteLine(result.Content[0].Text);
1238````
1239
830````ruby1240````ruby
831require "openai"1241require "openai"
832 1242
1087 return completion.choices[0].message.content1497 return completion.choices[0].message.content
1088```1498```
1089 1499
1500```go
1501import (
1502 "context"
1503 "fmt"
1504 "log"
1505
1506 "github.com/openai/openai-go/v3"
1507)
1508
1509func main() {
1510 if err := run(); err != nil {
1511 log.Fatal(err)
1512 }
1513}
1514
1515func run() error {
1516 client := openai.NewClient()
1517 metaPrompt := "Given a current prompt and a change description, produce a detailed system prompt to guide a realtime audio output language model in completing the task effectively.\n" +
1518 "\n" +
1519 "Your final output will be the full corrected prompt verbatim. However, before that, at the very beginning of your response, use <reasoning> tags to analyze the prompt and determine the following, explicitly:\n" +
1520 "<reasoning>\n" +
1521 "- Simple Change: (yes/no) Is the change description explicit and simple? (If so, skip the rest of these questions.)\n" +
1522 "- Reasoning: (yes/no) Does the current prompt use reasoning, analysis, or chain of thought?\n" +
1523 " - Identify: (max 10 words) if so, which section(s) utilize reasoning?\n" +
1524 " - Conclusion: (yes/no) is the chain of thought used to determine a conclusion?\n" +
1525 " - Ordering: (before/after) is the chain of though located before or after\n" +
1526 "- Structure: (yes/no) does the input prompt have a well defined structure\n" +
1527 "- Examples: (yes/no) does the input prompt have few-shot examples\n" +
1528 " - Representative: (1-5) if present, how representative are the examples?\n" +
1529 "- Complexity: (1-5) how complex is the input prompt?\n" +
1530 " - Task: (1-5) how complex is the implied task?\n" +
1531 " - Necessity: ()\n" +
1532 "- Specificity: (1-5) how detailed and specific is the prompt? (not to be confused with length)\n" +
1533 "- Prioritization: (list) what 1-3 categories are the MOST important to address.\n" +
1534 "- Conclusion: (max 30 words) given the previous assessment, give a very concise, imperative description of what should be changed and how. this does not have to adhere strictly to only the categories listed\n" +
1535 "</reasoning>\n" +
1536 "\n" +
1537 "# Guidelines\n" +
1538 "\n" +
1539 "- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.\n" +
1540 "- Tone: Make sure to specifically call out the tone. By default it should be emotive and friendly, and speak quickly to avoid keeping the user just waiting.\n" +
1541 "- Audio Output Constraints: Because the model is outputting audio, the responses should be short and conversational.\n" +
1542 "- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.\n" +
1543 "- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.\n" +
1544 " - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.\n" +
1545 " - It is very important that any examples included reflect the short, conversational output responses of the model.\n" +
1546 "Keep the sentences very short by default. Instead of 3 sentences in a row by the assistant, it should be split up with a back and forth with the user instead.\n" +
1547 " - By default each sentence should be a few words only (5-20ish words). However, if the user specifically asks for \"short\" responses, then the examples should truly have 1-10 word responses max.\n" +
1548 " - Make sure the examples are multi-turn (at least 4 back-forth-back-forth per example), not just one questions an response. They should reflect an organic conversation.\n" +
1549 "- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.\n" +
1550 "- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.\n" +
1551 "- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.\n" +
1552 "\n" +
1553 "The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no \"---\")\n" +
1554 "\n" +
1555 "[Concise instruction describing the task - this should be the first line in the prompt, no section header]\n" +
1556 "\n" +
1557 "[Additional details as needed.]\n" +
1558 "\n" +
1559 "[Optional sections with headings or bullet points for detailed steps.]\n" +
1560 "\n" +
1561 "# Examples [optional]\n" +
1562 "\n" +
1563 "[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]\n" +
1564 "[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]\n" +
1565 "\n" +
1566 "# Notes [optional]\n" +
1567 "\n" +
1568 "[optional: edge cases, details, and an area to call or repeat out specific important considerations]\n" +
1569 "[NOTE: you must start with a <reasoning> section. the immediate next token you produce should be <reasoning>]\n"
1570 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
1571 Model: "gpt-6-astra",
1572 Messages: []openai.ChatCompletionMessageParamUnion{
1573 openai.SystemMessage(metaPrompt), openai.UserMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue."),
1574 }})
1575 if err != nil {
1576 return err
1577 }
1578 fmt.Println(completion.Choices[0].Message.Content)
1579 return nil
1580}
1581```
1582
1090```java1583```java
1091import com.openai.client.OpenAIClient;1584import com.openai.client.OpenAIClient;
1092import com.openai.client.okhttp.OpenAIOkHttpClient;1585import com.openai.client.okhttp.OpenAIOkHttpClient;
1163 .forEach(System.out::println);1656 .forEach(System.out::println);
1164```1657```
1165 1658
1659```csharp
1660using OpenAI.Chat;
1661
1662string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
1663string model = "gpt-6-astra";
1664ChatClient client = new(model, key);
1665
1666string metaPrompt = """"
1667 Given a current prompt and a change description, produce a detailed system prompt to guide a realtime audio output language model in completing the task effectively.
1668
1669 Your final output will be the full corrected prompt verbatim. However, before that, at the very beginning of your response, use <reasoning> tags to analyze the prompt and determine the following, explicitly:
1670 <reasoning>
1671 - Simple Change: (yes/no) Is the change description explicit and simple? (If so, skip the rest of these questions.)
1672 - Reasoning: (yes/no) Does the current prompt use reasoning, analysis, or chain of thought?
1673 - Identify: (max 10 words) if so, which section(s) utilize reasoning?
1674 - Conclusion: (yes/no) is the chain of thought used to determine a conclusion?
1675 - Ordering: (before/after) is the chain of though located before or after
1676 - Structure: (yes/no) does the input prompt have a well defined structure
1677 - Examples: (yes/no) does the input prompt have few-shot examples
1678 - Representative: (1-5) if present, how representative are the examples?
1679 - Complexity: (1-5) how complex is the input prompt?
1680 - Task: (1-5) how complex is the implied task?
1681 - Necessity: ()
1682 - Specificity: (1-5) how detailed and specific is the prompt? (not to be confused with length)
1683 - Prioritization: (list) what 1-3 categories are the MOST important to address.
1684 - Conclusion: (max 30 words) given the previous assessment, give a very concise, imperative description of what should be changed and how. this does not have to adhere strictly to only the categories listed
1685 </reasoning>
1686
1687 # Guidelines
1688
1689 - Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
1690 - Tone: Make sure to specifically call out the tone. By default it should be emotive and friendly, and speak quickly to avoid keeping the user just waiting.
1691 - Audio Output Constraints: Because the model is outputting audio, the responses should be short and conversational.
1692 - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
1693 - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
1694 - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
1695 - It is very important that any examples included reflect the short, conversational output responses of the model.
1696 Keep the sentences very short by default. Instead of 3 sentences in a row by the assistant, it should be split up with a back and forth with the user instead.
1697 - By default each sentence should be a few words only (5-20ish words). However, if the user specifically asks for "short" responses, then the examples should truly have 1-10 word responses max.
1698 - Make sure the examples are multi-turn (at least 4 back-forth-back-forth per example), not just one questions an response. They should reflect an organic conversation.
1699 - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
1700 - Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
1701 - Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
1702
1703 The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
1704
1705 [Concise instruction describing the task - this should be the first line in the prompt, no section header]
1706
1707 [Additional details as needed.]
1708
1709 [Optional sections with headings or bullet points for detailed steps.]
1710
1711 # Examples [optional]
1712
1713 [Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
1714 [If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
1715
1716 # Notes [optional]
1717
1718 [optional: edge cases, details, and an area to call or repeat out specific important considerations]
1719 [NOTE: you must start with a <reasoning> section. the immediate next token you produce should be <reasoning>]
1720 """";
1721ChatCompletionOptions options = new();
1722ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Task, Goal, or Current Prompt: Help a customer resolve a billing issue.")], options);
1723Console.WriteLine(result.Content[0].Text);
1724```
1725
1166```ruby1726```ruby
1167require "openai"1727require "openai"
1168 1728
1860 return json.loads(completion.choices[0].message.content)2420 return json.loads(completion.choices[0].message.content)
1861```2421```
1862 2422
1863```java2423```go
1864import com.openai.client.OpenAIClient;2424import (
1865import com.openai.client.okhttp.OpenAIOkHttpClient;2425 "context"
1866import com.openai.core.JsonValue;2426 "encoding/json"
1867import com.openai.models.chat.completions.ChatCompletionCreateParams;2427 "fmt"
1868import java.util.List;2428 "log"
1869import java.util.Map;
1870 2429
1871String metaPrompt =2430 "github.com/openai/openai-go/v3"
1872 """2431 "github.com/openai/openai-go/v3/shared"
1873 # Instructions2432)
1874 Return a valid schema for the described JSON.2433
2434func main() {
2435 if err := run(); err != nil {
2436 log.Fatal(err)
2437 }
2438}
2439
2440func run() error {
2441 client := openai.NewClient()
2442 metaPrompt := "# Instructions\n" +
2443 "Return a valid schema for the described JSON.\n" +
2444 "\n" +
2445 "You must also make sure:\n" +
2446 "- all fields in an object are set as required\n" +
2447 "- I REPEAT, ALL FIELDS MUST BE MARKED AS REQUIRED\n" +
2448 "- all objects must have additionalProperties set to false\n" +
2449 " - because of this, some cases like \"attributes\" or \"metadata\" properties that would normally allow additional properties should instead have a fixed set of properties\n" +
2450 "- all objects must have properties defined\n" +
2451 "- field order matters. any form of \"thinking\" or \"explanation\" should come before the conclusion\n" +
2452 "- $defs must be defined under the schema param\n" +
2453 "\n" +
2454 "Notable keywords NOT supported include:\n" +
2455 "- For objects: unevaluatedProperties, propertyNames, minProperties, maxProperties\n" +
2456 "- For arrays: unevaluatedItems, contains, minContains, maxContains, uniqueItems\n" +
2457 "\n" +
2458 "Other notes:\n" +
2459 "- definitions and recursion are supported\n" +
2460 "- only if necessary to include references e.g. \"$defs\", it must be inside the \"schema\" object\n" +
2461 "\n" +
2462 "# Examples\n" +
2463 "Input: Generate a math reasoning schema with steps and a final answer.\n" +
2464 "Output: {\n" +
2465 " \"name\": \"math_reasoning\",\n" +
2466 " \"type\": \"object\",\n" +
2467 " \"properties\": {\n" +
2468 " \"steps\": {\n" +
2469 " \"type\": \"array\",\n" +
2470 " \"description\": \"A sequence of steps involved in solving the math problem.\",\n" +
2471 " \"items\": {\n" +
2472 " \"type\": \"object\",\n" +
2473 " \"properties\": {\n" +
2474 " \"explanation\": {\n" +
2475 " \"type\": \"string\",\n" +
2476 " \"description\": \"Description of the reasoning or method used in this step.\"\n" +
2477 " },\n" +
2478 " \"output\": {\n" +
2479 " \"type\": \"string\",\n" +
2480 " \"description\": \"Result or outcome of this specific step.\"\n" +
2481 " }\n" +
2482 " },\n" +
2483 " \"required\": [\n" +
2484 " \"explanation\",\n" +
2485 " \"output\"\n" +
2486 " ],\n" +
2487 " \"additionalProperties\": false\n" +
2488 " }\n" +
2489 " },\n" +
2490 " \"final_answer\": {\n" +
2491 " \"type\": \"string\",\n" +
2492 " \"description\": \"The final solution or answer to the math problem.\"\n" +
2493 " }\n" +
2494 " },\n" +
2495 " \"required\": [\n" +
2496 " \"steps\",\n" +
2497 " \"final_answer\"\n" +
2498 " ],\n" +
2499 " \"additionalProperties\": false\n" +
2500 "}\n" +
2501 "\n" +
2502 "Input: Give me a linked list\n" +
2503 "Output: {\n" +
2504 " \"name\": \"linked_list\",\n" +
2505 " \"type\": \"object\",\n" +
2506 " \"properties\": {\n" +
2507 " \"linked_list\": {\n" +
2508 " \"$ref\": \"#/$defs/linked_list_node\",\n" +
2509 " \"description\": \"The head node of the linked list.\"\n" +
2510 " }\n" +
2511 " },\n" +
2512 " \"$defs\": {\n" +
2513 " \"linked_list_node\": {\n" +
2514 " \"type\": \"object\",\n" +
2515 " \"description\": \"Defines a node in a singly linked list.\",\n" +
2516 " \"properties\": {\n" +
2517 " \"value\": {\n" +
2518 " \"type\": \"number\",\n" +
2519 " \"description\": \"The value stored in this node.\"\n" +
2520 " },\n" +
2521 " \"next\": {\n" +
2522 " \"anyOf\": [\n" +
2523 " {\n" +
2524 " \"$ref\": \"#/$defs/linked_list_node\"\n" +
2525 " },\n" +
2526 " {\n" +
2527 " \"type\": \"null\"\n" +
2528 " }\n" +
2529 " ],\n" +
2530 " \"description\": \"Reference to the next node; null if it is the last node.\"\n" +
2531 " }\n" +
2532 " },\n" +
2533 " \"required\": [\n" +
2534 " \"value\",\n" +
2535 " \"next\"\n" +
2536 " ],\n" +
2537 " \"additionalProperties\": false\n" +
2538 " }\n" +
2539 " },\n" +
2540 " \"required\": [\n" +
2541 " \"linked_list\"\n" +
2542 " ],\n" +
2543 " \"additionalProperties\": false\n" +
2544 "}\n" +
2545 "\n" +
2546 "Input: Dynamically generated UI\n" +
2547 "Output: {\n" +
2548 " \"name\": \"ui\",\n" +
2549 " \"type\": \"object\",\n" +
2550 " \"properties\": {\n" +
2551 " \"type\": {\n" +
2552 " \"type\": \"string\",\n" +
2553 " \"description\": \"The type of the UI component\",\n" +
2554 " \"enum\": [\n" +
2555 " \"div\",\n" +
2556 " \"button\",\n" +
2557 " \"header\",\n" +
2558 " \"section\",\n" +
2559 " \"field\",\n" +
2560 " \"form\"\n" +
2561 " ]\n" +
2562 " },\n" +
2563 " \"label\": {\n" +
2564 " \"type\": \"string\",\n" +
2565 " \"description\": \"The label of the UI component, used for buttons or form fields\"\n" +
2566 " },\n" +
2567 " \"children\": {\n" +
2568 " \"type\": \"array\",\n" +
2569 " \"description\": \"Nested UI components\",\n" +
2570 " \"items\": {\n" +
2571 " \"$ref\": \"#\"\n" +
2572 " }\n" +
2573 " },\n" +
2574 " \"attributes\": {\n" +
2575 " \"type\": \"array\",\n" +
2576 " \"description\": \"Arbitrary attributes for the UI component, suitable for any element\",\n" +
2577 " \"items\": {\n" +
2578 " \"type\": \"object\",\n" +
2579 " \"properties\": {\n" +
2580 " \"name\": {\n" +
2581 " \"type\": \"string\",\n" +
2582 " \"description\": \"The name of the attribute, for example onClick or className\"\n" +
2583 " },\n" +
2584 " \"value\": {\n" +
2585 " \"type\": \"string\",\n" +
2586 " \"description\": \"The value of the attribute\"\n" +
2587 " }\n" +
2588 " },\n" +
2589 " \"required\": [\n" +
2590 " \"name\",\n" +
2591 " \"value\"\n" +
2592 " ],\n" +
2593 " \"additionalProperties\": false\n" +
2594 " }\n" +
2595 " }\n" +
2596 " },\n" +
2597 " \"required\": [\n" +
2598 " \"type\",\n" +
2599 " \"label\",\n" +
2600 " \"children\",\n" +
2601 " \"attributes\"\n" +
2602 " ],\n" +
2603 " \"additionalProperties\": false\n" +
2604 "}\n"
2605 var schema map[string]any
2606 if err := json.Unmarshal([]byte(`{
2607 "type": "object",
2608 "properties": {
2609 "name": {
2610 "type": "string",
2611 "description": "The name of the schema"
2612 },
2613 "type": {
2614 "type": "string",
2615 "enum": [
2616 "object",
2617 "array",
2618 "string",
2619 "number",
2620 "boolean",
2621 "null"
2622 ]
2623 },
2624 "properties": {
2625 "type": "object",
2626 "additionalProperties": {
2627 "$ref": "#/$defs/schema_definition"
2628 }
2629 },
2630 "items": {
2631 "anyOf": [
2632 {
2633 "$ref": "#/$defs/schema_definition"
2634 },
2635 {
2636 "type": "array",
2637 "items": {
2638 "$ref": "#/$defs/schema_definition"
2639 }
2640 }
2641 ]
2642 },
2643 "required": {
2644 "type": "array",
2645 "items": {
2646 "type": "string"
2647 }
2648 },
2649 "additionalProperties": {
2650 "type": "boolean"
2651 }
2652 },
2653 "required": [
2654 "type"
2655 ],
2656 "additionalProperties": false,
2657 "if": {
2658 "properties": {
2659 "type": {
2660 "const": "object"
2661 }
2662 }
2663 },
2664 "then": {
2665 "required": [
2666 "properties"
2667 ]
2668 },
2669 "$defs": {
2670 "schema_definition": {
2671 "type": "object",
2672 "properties": {
2673 "type": {
2674 "type": "string",
2675 "enum": [
2676 "object",
2677 "array",
2678 "string",
2679 "number",
2680 "boolean",
2681 "null"
2682 ]
2683 },
2684 "properties": {
2685 "type": "object",
2686 "additionalProperties": {
2687 "$ref": "#/$defs/schema_definition"
2688 }
2689 },
2690 "items": {
2691 "anyOf": [
2692 {
2693 "$ref": "#/$defs/schema_definition"
2694 },
2695 {
2696 "type": "array",
2697 "items": {
2698 "$ref": "#/$defs/schema_definition"
2699 }
2700 }
2701 ]
2702 },
2703 "required": {
2704 "type": "array",
2705 "items": {
2706 "type": "string"
2707 }
2708 },
2709 "additionalProperties": {
2710 "type": "boolean"
2711 }
2712 },
2713 "required": [
2714 "type"
2715 ],
2716 "additionalProperties": false,
2717 "if": {
2718 "properties": {
2719 "type": {
2720 "const": "object"
2721 }
2722 }
2723 },
2724 "then": {
2725 "required": [
2726 "properties"
2727 ]
2728 }
2729 }
2730 }
2731}`), &schema); err != nil {
2732 return err
2733 }
2734 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
2735 Model: "gpt-5.6-terra",
2736 Messages: []openai.ChatCompletionMessageParamUnion{
2737 openai.SystemMessage(metaPrompt), openai.UserMessage("Description: Schedule a meeting with a title and start time."),
2738 }, ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{OfJSONSchema: &shared.ResponseFormatJSONSchemaParam{JSONSchema: shared.ResponseFormatJSONSchemaJSONSchemaParam{Name: "metaschema", Schema: schema}}}})
2739 if err != nil {
2740 return err
2741 }
2742 var result any
2743 if err := json.Unmarshal([]byte(completion.Choices[0].Message.Content), &result); err != nil {
2744 return err
2745 }
2746 encoded, err := json.MarshalIndent(result, "", " ")
2747 if err != nil {
2748 return err
2749 }
2750 fmt.Println(string(encoded))
2751 return nil
2752}
2753```
2754
2755```java
2756import com.openai.client.OpenAIClient;
2757import com.openai.client.okhttp.OpenAIOkHttpClient;
2758import com.openai.core.JsonValue;
2759import com.openai.models.chat.completions.ChatCompletionCreateParams;
2760import java.util.List;
2761import java.util.Map;
2762
2763String metaPrompt =
2764 """
2765 # Instructions
2766 Return a valid schema for the described JSON.
1875 2767
1876 You must also make sure:2768 You must also make sure:
1877 - all fields in an object are set as required2769 - all fields in an object are set as required
2193 .forEach(System.out::println);3085 .forEach(System.out::println);
2194```3086```
2195 3087
2196```ruby3088```csharp
2197require "openai"3089using System.Text.Json;
2198require "json"3090using OpenAI.Chat;
2199 3091
2200META_SCHEMA = {3092string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
2201 "name" => "metaschema",3093string model = "gpt-5.6-terra";
2202 "schema" => {3094ChatClient client = new(model, key);
2203 "type" => "object",
2204 "properties" => {
2205 "name" => {
2206 "type" => "string",
2207 "description" => "The name of the schema"
2208 },
2209 "type" => {
2210 "type" => "string",
2211 "enum" => ["object", "array", "string", "number", "boolean", "null"]
2212 },
2213 "properties" => {
2214 "type" => "object",
2215 "additionalProperties" => {
2216 "$ref" => "#/$defs/schema_definition"
2217 }
2218 },
2219 "items" => {
2220 "anyOf" => [
2221 {
2222 "$ref" => "#/$defs/schema_definition"
2223 }, {
2224 "type" => "array",
2225 "items" => {
2226 "$ref" => "#/$defs/schema_definition"
2227 }
2228 }
2229 ]
2230 },
2231 "required" => {
2232 "type" => "array",
2233 "items" => {
2234 "type" => "string"
2235 }
2236 },
2237 "additionalProperties" => {
2238 "type" => "boolean"
2239 }
2240 },
2241 "required" => ["type"],
2242 "additionalProperties" => false,
2243 "if" => {
2244 "properties" => {
2245 "type" => {
2246 "const" => "object"
2247 }
2248 }
2249 },
2250 "then" => {
2251 "required" => ["properties"]
2252 },
2253 "$defs" => {
2254 "schema_definition" => {
2255 "type" => "object",
2256 "properties" => {
2257 "type" => {
2258 "type" => "string",
2259 "enum" => ["object", "array", "string", "number", "boolean", "null"]
2260 },
2261 "properties" => {
2262 "type" => "object",
2263 "additionalProperties" => {
2264 "$ref" => "#/$defs/schema_definition"
2265 }
2266 },
2267 "items" => {
2268 "anyOf" => [
2269 {
2270 "$ref" => "#/$defs/schema_definition"
2271 }, {
2272 "type" => "array",
2273 "items" => {
2274 "$ref" => "#/$defs/schema_definition"
2275 }
2276 }
2277 ]
2278 },
2279 "required" => {
2280 "type" => "array",
2281 "items" => {
2282 "type" => "string"
2283 }
2284 },
2285 "additionalProperties" => {
2286 "type" => "boolean"
2287 }
2288 },
2289 "required" => ["type"],
2290 "additionalProperties" => false,
2291 "if" => {
2292 "properties" => {
2293 "type" => {
2294 "const" => "object"
2295 }
2296 }
2297 },
2298 "then" => {
2299 "required" => ["properties"]
2300 }
2301 }
2302 }
2303 }
2304}
2305 3095
2306META_PROMPT = <<~PROMPT.strip3096string metaPrompt = """"
2307 # Instructions3097 # Instructions
2308 Return a valid schema for the described JSON.3098 Return a valid schema for the described JSON.
2309 3099
2467 ],3257 ],
2468 "additionalProperties": false3258 "additionalProperties": false
2469 }3259 }
2470PROMPT3260 """";
2471 3261ChatCompletionOptions options = new();
2472client = OpenAI::Client.new3262options.ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat("metaschema", BinaryData.FromString("""
2473completion = client.chat.completions.create(
2474 model: "gpt-5.6-terra",
2475 response_format: {
2476 type: :json_schema,
2477 json_schema: META_SCHEMA
2478 },
2479 messages: [
2480 {3263 {
2481 role: :system,3264 "type": "object",
2482 content: META_PROMPT3265 "properties": {
3266 "name": {
3267 "type": "string",
3268 "description": "The name of the schema"
2483 },3269 },
2484 {3270 "type": {
2485 role: :user,3271 "type": "string",
2486 content: "Description: Schedule a meeting with a title and start time."3272 "enum": [
2487 }3273 "object",
3274 "array",
3275 "string",
3276 "number",
3277 "boolean",
3278 "null"
2488 ]3279 ]
2489)3280 },
2490message = completion.choices.fetch(0).message3281 "properties": {
2491raise "Schema generation refused: #{message.refusal}" if message.refusal3282 "type": "object",
3283 "additionalProperties": {
3284 "$ref": "#/$defs/schema_definition"
3285 }
3286 },
3287 "items": {
3288 "anyOf": [
3289 {
3290 "$ref": "#/$defs/schema_definition"
3291 },
3292 {
3293 "type": "array",
3294 "items": {
3295 "$ref": "#/$defs/schema_definition"
3296 }
3297 }
3298 ]
3299 },
3300 "required": {
3301 "type": "array",
3302 "items": {
3303 "type": "string"
3304 }
3305 },
3306 "additionalProperties": {
3307 "type": "boolean"
3308 }
3309 },
3310 "required": [
3311 "type"
3312 ],
3313 "additionalProperties": false,
3314 "if": {
3315 "properties": {
3316 "type": {
3317 "const": "object"
3318 }
3319 }
3320 },
3321 "then": {
3322 "required": [
3323 "properties"
3324 ]
3325 },
3326 "$defs": {
3327 "schema_definition": {
3328 "type": "object",
3329 "properties": {
3330 "type": {
3331 "type": "string",
3332 "enum": [
3333 "object",
3334 "array",
3335 "string",
3336 "number",
3337 "boolean",
3338 "null"
3339 ]
3340 },
3341 "properties": {
3342 "type": "object",
3343 "additionalProperties": {
3344 "$ref": "#/$defs/schema_definition"
3345 }
3346 },
3347 "items": {
3348 "anyOf": [
3349 {
3350 "$ref": "#/$defs/schema_definition"
3351 },
3352 {
3353 "type": "array",
3354 "items": {
3355 "$ref": "#/$defs/schema_definition"
3356 }
3357 }
3358 ]
3359 },
3360 "required": {
3361 "type": "array",
3362 "items": {
3363 "type": "string"
3364 }
3365 },
3366 "additionalProperties": {
3367 "type": "boolean"
3368 }
3369 },
3370 "required": [
3371 "type"
3372 ],
3373 "additionalProperties": false,
3374 "if": {
3375 "properties": {
3376 "type": {
3377 "const": "object"
3378 }
3379 }
3380 },
3381 "then": {
3382 "required": [
3383 "properties"
3384 ]
3385 }
3386 }
3387 }
3388 }
3389 """));
3390ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Description: Schedule a meeting with a title and start time.")], options);
3391using JsonDocument parsed = JsonDocument.Parse(result.Content[0].Text);
3392Console.WriteLine(parsed.RootElement);
3393```
3394
3395```ruby
3396require "openai"
3397require "json"
3398
3399META_SCHEMA = {
3400 "name" => "metaschema",
3401 "schema" => {
3402 "type" => "object",
3403 "properties" => {
3404 "name" => {
3405 "type" => "string",
3406 "description" => "The name of the schema"
3407 },
3408 "type" => {
3409 "type" => "string",
3410 "enum" => ["object", "array", "string", "number", "boolean", "null"]
3411 },
3412 "properties" => {
3413 "type" => "object",
3414 "additionalProperties" => {
3415 "$ref" => "#/$defs/schema_definition"
3416 }
3417 },
3418 "items" => {
3419 "anyOf" => [
3420 {
3421 "$ref" => "#/$defs/schema_definition"
3422 }, {
3423 "type" => "array",
3424 "items" => {
3425 "$ref" => "#/$defs/schema_definition"
3426 }
3427 }
3428 ]
3429 },
3430 "required" => {
3431 "type" => "array",
3432 "items" => {
3433 "type" => "string"
3434 }
3435 },
3436 "additionalProperties" => {
3437 "type" => "boolean"
3438 }
3439 },
3440 "required" => ["type"],
3441 "additionalProperties" => false,
3442 "if" => {
3443 "properties" => {
3444 "type" => {
3445 "const" => "object"
3446 }
3447 }
3448 },
3449 "then" => {
3450 "required" => ["properties"]
3451 },
3452 "$defs" => {
3453 "schema_definition" => {
3454 "type" => "object",
3455 "properties" => {
3456 "type" => {
3457 "type" => "string",
3458 "enum" => ["object", "array", "string", "number", "boolean", "null"]
3459 },
3460 "properties" => {
3461 "type" => "object",
3462 "additionalProperties" => {
3463 "$ref" => "#/$defs/schema_definition"
3464 }
3465 },
3466 "items" => {
3467 "anyOf" => [
3468 {
3469 "$ref" => "#/$defs/schema_definition"
3470 }, {
3471 "type" => "array",
3472 "items" => {
3473 "$ref" => "#/$defs/schema_definition"
3474 }
3475 }
3476 ]
3477 },
3478 "required" => {
3479 "type" => "array",
3480 "items" => {
3481 "type" => "string"
3482 }
3483 },
3484 "additionalProperties" => {
3485 "type" => "boolean"
3486 }
3487 },
3488 "required" => ["type"],
3489 "additionalProperties" => false,
3490 "if" => {
3491 "properties" => {
3492 "type" => {
3493 "const" => "object"
3494 }
3495 }
3496 },
3497 "then" => {
3498 "required" => ["properties"]
3499 }
3500 }
3501 }
3502 }
3503}
3504
3505META_PROMPT = <<~PROMPT.strip
3506 # Instructions
3507 Return a valid schema for the described JSON.
3508
3509 You must also make sure:
3510 - all fields in an object are set as required
3511 - I REPEAT, ALL FIELDS MUST BE MARKED AS REQUIRED
3512 - all objects must have additionalProperties set to false
3513 - because of this, some cases like "attributes" or "metadata" properties that would normally allow additional properties should instead have a fixed set of properties
3514 - all objects must have properties defined
3515 - field order matters. any form of "thinking" or "explanation" should come before the conclusion
3516 - $defs must be defined under the schema param
3517
3518 Notable keywords NOT supported include:
3519 - For objects: unevaluatedProperties, propertyNames, minProperties, maxProperties
3520 - For arrays: unevaluatedItems, contains, minContains, maxContains, uniqueItems
3521
3522 Other notes:
3523 - definitions and recursion are supported
3524 - only if necessary to include references e.g. "$defs", it must be inside the "schema" object
3525
3526 # Examples
3527 Input: Generate a math reasoning schema with steps and a final answer.
3528 Output: {
3529 "name": "math_reasoning",
3530 "type": "object",
3531 "properties": {
3532 "steps": {
3533 "type": "array",
3534 "description": "A sequence of steps involved in solving the math problem.",
3535 "items": {
3536 "type": "object",
3537 "properties": {
3538 "explanation": {
3539 "type": "string",
3540 "description": "Description of the reasoning or method used in this step."
3541 },
3542 "output": {
3543 "type": "string",
3544 "description": "Result or outcome of this specific step."
3545 }
3546 },
3547 "required": [
3548 "explanation",
3549 "output"
3550 ],
3551 "additionalProperties": false
3552 }
3553 },
3554 "final_answer": {
3555 "type": "string",
3556 "description": "The final solution or answer to the math problem."
3557 }
3558 },
3559 "required": [
3560 "steps",
3561 "final_answer"
3562 ],
3563 "additionalProperties": false
3564 }
3565
3566 Input: Give me a linked list
3567 Output: {
3568 "name": "linked_list",
3569 "type": "object",
3570 "properties": {
3571 "linked_list": {
3572 "$ref": "#/$defs/linked_list_node",
3573 "description": "The head node of the linked list."
3574 }
3575 },
3576 "$defs": {
3577 "linked_list_node": {
3578 "type": "object",
3579 "description": "Defines a node in a singly linked list.",
3580 "properties": {
3581 "value": {
3582 "type": "number",
3583 "description": "The value stored in this node."
3584 },
3585 "next": {
3586 "anyOf": [
3587 {
3588 "$ref": "#/$defs/linked_list_node"
3589 },
3590 {
3591 "type": "null"
3592 }
3593 ],
3594 "description": "Reference to the next node; null if it is the last node."
3595 }
3596 },
3597 "required": [
3598 "value",
3599 "next"
3600 ],
3601 "additionalProperties": false
3602 }
3603 },
3604 "required": [
3605 "linked_list"
3606 ],
3607 "additionalProperties": false
3608 }
3609
3610 Input: Dynamically generated UI
3611 Output: {
3612 "name": "ui",
3613 "type": "object",
3614 "properties": {
3615 "type": {
3616 "type": "string",
3617 "description": "The type of the UI component",
3618 "enum": [
3619 "div",
3620 "button",
3621 "header",
3622 "section",
3623 "field",
3624 "form"
3625 ]
3626 },
3627 "label": {
3628 "type": "string",
3629 "description": "The label of the UI component, used for buttons or form fields"
3630 },
3631 "children": {
3632 "type": "array",
3633 "description": "Nested UI components",
3634 "items": {
3635 "$ref": "#"
3636 }
3637 },
3638 "attributes": {
3639 "type": "array",
3640 "description": "Arbitrary attributes for the UI component, suitable for any element",
3641 "items": {
3642 "type": "object",
3643 "properties": {
3644 "name": {
3645 "type": "string",
3646 "description": "The name of the attribute, for example onClick or className"
3647 },
3648 "value": {
3649 "type": "string",
3650 "description": "The value of the attribute"
3651 }
3652 },
3653 "required": [
3654 "name",
3655 "value"
3656 ],
3657 "additionalProperties": false
3658 }
3659 }
3660 },
3661 "required": [
3662 "type",
3663 "label",
3664 "children",
3665 "attributes"
3666 ],
3667 "additionalProperties": false
3668 }
3669PROMPT
3670
3671client = OpenAI::Client.new
3672completion = client.chat.completions.create(
3673 model: "gpt-5.6-terra",
3674 response_format: {
3675 type: :json_schema,
3676 json_schema: META_SCHEMA
3677 },
3678 messages: [
3679 {
3680 role: :system,
3681 content: META_PROMPT
3682 },
3683 {
3684 role: :user,
3685 content: "Description: Schedule a meeting with a title and start time."
3686 }
3687 ]
3688)
3689message = completion.choices.fetch(0).message
3690raise "Schema generation refused: #{message.refusal}" if message.refusal
2492 3691
2493puts(JSON.pretty_generate(JSON.parse(message.content || raise("No schema returned"))))3692puts(JSON.pretty_generate(JSON.parse(message.content || raise("No schema returned"))))
2494```3693```
2802Pay special attention to making sure that "required" and "type" are always at the correct level of nesting. For example, "required" should be at the same level as "properties", not inside it.4001Pay special attention to making sure that "required" and "type" are always at the correct level of nesting. For example, "required" should be at the same level as "properties", not inside it.
2803Make sure that every property, no matter how short, has a type and description correctly nested inside it.4002Make sure that every property, no matter how short, has a type and description correctly nested inside it.
2804 4003
2805# Examples4004# Examples
2806Input: Assign values to NN hyperparameters4005Input: Assign values to NN hyperparameters
2807Output: {4006Output: {
4007 "name": "set_hyperparameters",
4008 "description": "Assign values to NN hyperparameters",
4009 "parameters": {
4010 "type": "object",
4011 "required": [
4012 "learning_rate",
4013 "epochs"
4014 ],
4015 "properties": {
4016 "epochs": {
4017 "type": "number",
4018 "description": "Number of complete passes through dataset"
4019 },
4020 "learning_rate": {
4021 "type": "number",
4022 "description": "Speed of model learning"
4023 }
4024 }
4025 }
4026}
4027
4028Input: Plans a motion path for the robot
4029Output: {
4030 "name": "plan_motion",
4031 "description": "Plans a motion path for the robot",
4032 "parameters": {
4033 "type": "object",
4034 "required": [
4035 "start_position",
4036 "end_position"
4037 ],
4038 "properties": {
4039 "end_position": {
4040 "type": "object",
4041 "properties": {
4042 "x": {
4043 "type": "number",
4044 "description": "End X coordinate"
4045 },
4046 "y": {
4047 "type": "number",
4048 "description": "End Y coordinate"
4049 }
4050 }
4051 },
4052 "obstacles": {
4053 "type": "array",
4054 "description": "Array of obstacle coordinates",
4055 "items": {
4056 "type": "object",
4057 "properties": {
4058 "x": {
4059 "type": "number",
4060 "description": "Obstacle X coordinate"
4061 },
4062 "y": {
4063 "type": "number",
4064 "description": "Obstacle Y coordinate"
4065 }
4066 }
4067 }
4068 },
4069 "start_position": {
4070 "type": "object",
4071 "properties": {
4072 "x": {
4073 "type": "number",
4074 "description": "Start X coordinate"
4075 },
4076 "y": {
4077 "type": "number",
4078 "description": "Start Y coordinate"
4079 }
4080 }
4081 }
4082 }
4083 }
4084}
4085
4086Input: Calculates various technical indicators
4087Output: {
4088 "name": "technical_indicator",
4089 "description": "Calculates various technical indicators",
4090 "parameters": {
4091 "type": "object",
4092 "required": [
4093 "ticker",
4094 "indicators"
4095 ],
4096 "properties": {
4097 "indicators": {
4098 "type": "array",
4099 "description": "List of technical indicators to calculate",
4100 "items": {
4101 "type": "string",
4102 "description": "Technical indicator",
4103 "enum": [
4104 "RSI",
4105 "MACD",
4106 "Bollinger_Bands",
4107 "Stochastic_Oscillator"
4108 ]
4109 }
4110 },
4111 "period": {
4112 "type": "number",
4113 "description": "Time period for the analysis"
4114 },
4115 "ticker": {
4116 "type": "string",
4117 "description": "Stock ticker symbol"
4118 }
4119 }
4120 }
4121}
4122""".strip()
4123
4124
4125def generate_function_schema(description: str):
4126 completion = client.chat.completions.create(
4127 model="gpt-5.6-terra",
4128 response_format={"type": "json_schema", "json_schema": META_SCHEMA},
4129 messages=[
4130 {
4131 "role": "system",
4132 "content": META_PROMPT,
4133 },
4134 {
4135 "role": "user",
4136 "content": "Description:\n" + description,
4137 },
4138 ],
4139 )
4140
4141 return json.loads(completion.choices[0].message.content)
4142```
4143
4144```go
4145import (
4146 "context"
4147 "encoding/json"
4148 "fmt"
4149 "log"
4150
4151 "github.com/openai/openai-go/v3"
4152 "github.com/openai/openai-go/v3/shared"
4153)
4154
4155func main() {
4156 if err := run(); err != nil {
4157 log.Fatal(err)
4158 }
4159}
4160
4161func run() error {
4162 client := openai.NewClient()
4163 metaPrompt := "# Instructions\n" +
4164 "Return a valid schema for the described function.\n" +
4165 "\n" +
4166 "Pay special attention to making sure that \"required\" and \"type\" are always at the correct level of nesting. For example, \"required\" should be at the same level as \"properties\", not inside it.\n" +
4167 "Make sure that every property, no matter how short, has a type and description correctly nested inside it.\n" +
4168 "\n" +
4169 "# Examples\n" +
4170 "Input: Assign values to NN hyperparameters\n" +
4171 "Output: {\n" +
4172 " \"name\": \"set_hyperparameters\",\n" +
4173 " \"description\": \"Assign values to NN hyperparameters\",\n" +
4174 " \"parameters\": {\n" +
4175 " \"type\": \"object\",\n" +
4176 " \"required\": [\n" +
4177 " \"learning_rate\",\n" +
4178 " \"epochs\"\n" +
4179 " ],\n" +
4180 " \"properties\": {\n" +
4181 " \"epochs\": {\n" +
4182 " \"type\": \"number\",\n" +
4183 " \"description\": \"Number of complete passes through dataset\"\n" +
4184 " },\n" +
4185 " \"learning_rate\": {\n" +
4186 " \"type\": \"number\",\n" +
4187 " \"description\": \"Speed of model learning\"\n" +
4188 " }\n" +
4189 " }\n" +
4190 " }\n" +
4191 "}\n" +
4192 "\n" +
4193 "Input: Plans a motion path for the robot\n" +
4194 "Output: {\n" +
4195 " \"name\": \"plan_motion\",\n" +
4196 " \"description\": \"Plans a motion path for the robot\",\n" +
4197 " \"parameters\": {\n" +
4198 " \"type\": \"object\",\n" +
4199 " \"required\": [\n" +
4200 " \"start_position\",\n" +
4201 " \"end_position\"\n" +
4202 " ],\n" +
4203 " \"properties\": {\n" +
4204 " \"end_position\": {\n" +
4205 " \"type\": \"object\",\n" +
4206 " \"properties\": {\n" +
4207 " \"x\": {\n" +
4208 " \"type\": \"number\",\n" +
4209 " \"description\": \"End X coordinate\"\n" +
4210 " },\n" +
4211 " \"y\": {\n" +
4212 " \"type\": \"number\",\n" +
4213 " \"description\": \"End Y coordinate\"\n" +
4214 " }\n" +
4215 " }\n" +
4216 " },\n" +
4217 " \"obstacles\": {\n" +
4218 " \"type\": \"array\",\n" +
4219 " \"description\": \"Array of obstacle coordinates\",\n" +
4220 " \"items\": {\n" +
4221 " \"type\": \"object\",\n" +
4222 " \"properties\": {\n" +
4223 " \"x\": {\n" +
4224 " \"type\": \"number\",\n" +
4225 " \"description\": \"Obstacle X coordinate\"\n" +
4226 " },\n" +
4227 " \"y\": {\n" +
4228 " \"type\": \"number\",\n" +
4229 " \"description\": \"Obstacle Y coordinate\"\n" +
4230 " }\n" +
4231 " }\n" +
4232 " }\n" +
4233 " },\n" +
4234 " \"start_position\": {\n" +
4235 " \"type\": \"object\",\n" +
4236 " \"properties\": {\n" +
4237 " \"x\": {\n" +
4238 " \"type\": \"number\",\n" +
4239 " \"description\": \"Start X coordinate\"\n" +
4240 " },\n" +
4241 " \"y\": {\n" +
4242 " \"type\": \"number\",\n" +
4243 " \"description\": \"Start Y coordinate\"\n" +
4244 " }\n" +
4245 " }\n" +
4246 " }\n" +
4247 " }\n" +
4248 " }\n" +
4249 "}\n" +
4250 "\n" +
4251 "Input: Calculates various technical indicators\n" +
4252 "Output: {\n" +
4253 " \"name\": \"technical_indicator\",\n" +
4254 " \"description\": \"Calculates various technical indicators\",\n" +
4255 " \"parameters\": {\n" +
4256 " \"type\": \"object\",\n" +
4257 " \"required\": [\n" +
4258 " \"ticker\",\n" +
4259 " \"indicators\"\n" +
4260 " ],\n" +
4261 " \"properties\": {\n" +
4262 " \"indicators\": {\n" +
4263 " \"type\": \"array\",\n" +
4264 " \"description\": \"List of technical indicators to calculate\",\n" +
4265 " \"items\": {\n" +
4266 " \"type\": \"string\",\n" +
4267 " \"description\": \"Technical indicator\",\n" +
4268 " \"enum\": [\n" +
4269 " \"RSI\",\n" +
4270 " \"MACD\",\n" +
4271 " \"Bollinger_Bands\",\n" +
4272 " \"Stochastic_Oscillator\"\n" +
4273 " ]\n" +
4274 " }\n" +
4275 " },\n" +
4276 " \"period\": {\n" +
4277 " \"type\": \"number\",\n" +
4278 " \"description\": \"Time period for the analysis\"\n" +
4279 " },\n" +
4280 " \"ticker\": {\n" +
4281 " \"type\": \"string\",\n" +
4282 " \"description\": \"Stock ticker symbol\"\n" +
4283 " }\n" +
4284 " }\n" +
4285 " }\n" +
4286 "}\n"
4287 var schema map[string]any
4288 if err := json.Unmarshal([]byte(`{
4289 "type": "object",
4290 "properties": {
4291 "name": {
4292 "type": "string",
4293 "description": "The name of the function"
4294 },
4295 "description": {
4296 "type": "string",
4297 "description": "A description of what the function does"
4298 },
4299 "parameters": {
4300 "$ref": "#/$defs/schema_definition",
4301 "description": "A JSON schema that defines the function's parameters"
4302 }
4303 },
4304 "required": [
4305 "name",
4306 "description",
4307 "parameters"
4308 ],
4309 "additionalProperties": false,
4310 "$defs": {
4311 "schema_definition": {
4312 "type": "object",
4313 "properties": {
4314 "type": {
4315 "type": "string",
4316 "enum": [
4317 "object",
4318 "array",
4319 "string",
4320 "number",
4321 "boolean",
4322 "null"
4323 ]
4324 },
4325 "properties": {
4326 "type": "object",
4327 "additionalProperties": {
4328 "$ref": "#/$defs/schema_definition"
4329 }
4330 },
4331 "items": {
4332 "anyOf": [
4333 {
4334 "$ref": "#/$defs/schema_definition"
4335 },
4336 {
4337 "type": "array",
4338 "items": {
4339 "$ref": "#/$defs/schema_definition"
4340 }
4341 }
4342 ]
4343 },
4344 "required": {
4345 "type": "array",
4346 "items": {
4347 "type": "string"
4348 }
4349 },
4350 "additionalProperties": {
4351 "type": "boolean"
4352 }
4353 },
4354 "required": [
4355 "type"
4356 ],
4357 "additionalProperties": false,
4358 "if": {
4359 "properties": {
4360 "type": {
4361 "const": "object"
4362 }
4363 }
4364 },
4365 "then": {
4366 "required": [
4367 "properties"
4368 ]
4369 }
4370 }
4371 }
4372}`), &schema); err != nil {
4373 return err
4374 }
4375 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
4376 Model: "gpt-5.6-terra",
4377 Messages: []openai.ChatCompletionMessageParamUnion{
4378 openai.SystemMessage(metaPrompt), openai.UserMessage("Description: Schedule a meeting with a title and start time."),
4379 }, ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{OfJSONSchema: &shared.ResponseFormatJSONSchemaParam{JSONSchema: shared.ResponseFormatJSONSchemaJSONSchemaParam{Name: "function-metaschema", Schema: schema}}}})
4380 if err != nil {
4381 return err
4382 }
4383 var result any
4384 if err := json.Unmarshal([]byte(completion.Choices[0].Message.Content), &result); err != nil {
4385 return err
4386 }
4387 encoded, err := json.MarshalIndent(result, "", " ")
4388 if err != nil {
4389 return err
4390 }
4391 fmt.Println(string(encoded))
4392 return nil
4393}
4394```
4395
4396```java
4397import com.openai.client.OpenAIClient;
4398import com.openai.client.okhttp.OpenAIOkHttpClient;
4399import com.openai.core.JsonValue;
4400import com.openai.models.chat.completions.ChatCompletionCreateParams;
4401import java.util.List;
4402import java.util.Map;
4403
4404String metaPrompt =
4405 """
4406 # Instructions
4407 Return a valid schema for the described function.
4408
4409 Pay special attention to making sure that "required" and "type" are always at the correct level of nesting. For example, "required" should be at the same level as "properties", not inside it.
4410 Make sure that every property, no matter how short, has a type and description correctly nested inside it.
4411
4412 # Examples
4413 Input: Assign values to NN hyperparameters
4414 Output: {
2808 "name": "set_hyperparameters",4415 "name": "set_hyperparameters",
2809 "description": "Assign values to NN hyperparameters",4416 "description": "Assign values to NN hyperparameters",
2810 "parameters": {4417 "parameters": {
2824 }4431 }
2825 }4432 }
2826 }4433 }
2827}4434 }
2828 4435
2829Input: Plans a motion path for the robot4436 Input: Plans a motion path for the robot
2830Output: {4437 Output: {
2831 "name": "plan_motion",4438 "name": "plan_motion",
2832 "description": "Plans a motion path for the robot",4439 "description": "Plans a motion path for the robot",
2833 "parameters": {4440 "parameters": {
2882 }4489 }
2883 }4490 }
2884 }4491 }
2885}4492 }
2886 4493
2887Input: Calculates various technical indicators4494 Input: Calculates various technical indicators
2888Output: {4495 Output: {
2889 "name": "technical_indicator",4496 "name": "technical_indicator",
2890 "description": "Calculates various technical indicators",4497 "description": "Calculates various technical indicators",
2891 "parameters": {4498 "parameters": {
2919 }4526 }
2920 }4527 }
2921 }4528 }
2922}4529 }
2923""".strip()4530 """
2924 4531 .strip();
4532Map<String, Object> schemaDefinition =
4533 Map.of(
4534 "type", "object",
4535 "properties",
4536 Map.of(
4537 "type",
4538 Map.of(
4539 "type",
4540 "string",
4541 "enum",
4542 List.of("object", "array", "string", "number", "boolean", "null")),
4543 "properties",
4544 Map.of(
4545 "type",
4546 "object",
4547 "additionalProperties",
4548 Map.of("$ref", "#/$defs/schema_definition")),
4549 "items",
4550 Map.of(
4551 "anyOf",
4552 List.of(
4553 Map.of("$ref", "#/$defs/schema_definition"),
4554 Map.of(
4555 "type",
4556 "array",
4557 "items",
4558 Map.of("$ref", "#/$defs/schema_definition")))),
4559 "required", Map.of("type", "array", "items", Map.of("type", "string")),
4560 "additionalProperties", Map.of("type", "boolean")),
4561 "required", List.of("type"),
4562 "additionalProperties", false,
4563 "if", Map.of("properties", Map.of("type", Map.of("const", "object"))),
4564 "then", Map.of("required", List.of("properties")));
4565Map<String, Object> functionSchema =
4566 Map.of(
4567 "type", "object",
4568 "properties",
4569 Map.of(
4570 "name", Map.of("type", "string", "description", "The name of the function"),
4571 "description",
4572 Map.of(
4573 "type",
4574 "string",
4575 "description",
4576 "A description of what the function does"),
4577 "parameters",
4578 Map.of(
4579 "$ref",
4580 "#/$defs/schema_definition",
4581 "description",
4582 "A JSON schema that defines the function's parameters")),
4583 "required", List.of("name", "description", "parameters"),
4584 "additionalProperties", false,
4585 "$defs", Map.of("schema_definition", schemaDefinition));
2925 4586
2926def generate_function_schema(description: str):4587ChatCompletionCreateParams params =
2927 completion = client.chat.completions.create(4588 ChatCompletionCreateParams.builder()
2928 model="gpt-5.6-terra",4589 .model("gpt-5.6-terra")
2929 response_format={"type": "json_schema", "json_schema": META_SCHEMA},4590 .addSystemMessage(metaPrompt)
2930 messages=[4591 .addUserMessage("Description:\nSchedule a meeting with a title and start time.")
2931 {4592 .putAdditionalBodyProperty(
2932 "role": "system",4593 "response_format",
2933 "content": META_PROMPT,4594 JsonValue.from(
2934 },4595 Map.of(
2935 {4596 "type",
2936 "role": "user",4597 "json_schema",
2937 "content": "Description:\n" + description,4598 "json_schema",
2938 },4599 Map.of("name", "function-metaschema", "schema", functionSchema))))
2939 ],4600 .build();
2940 )
2941 4601
2942 return json.loads(completion.choices[0].message.content)4602client.chat().completions().create(params).choices().stream()
4603 .flatMap(choice -> choice.message().content().stream())
4604 .forEach(System.out::println);
2943```4605```
2944 4606
2945```java4607```csharp
2946import com.openai.client.OpenAIClient;4608using System.Text.Json;
2947import com.openai.client.okhttp.OpenAIOkHttpClient;4609using OpenAI.Chat;
2948import com.openai.core.JsonValue;
2949import com.openai.models.chat.completions.ChatCompletionCreateParams;
2950import java.util.List;
2951import java.util.Map;
2952 4610
2953String metaPrompt =4611string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
2954 """4612string model = "gpt-5.6-terra";
4613ChatClient client = new(model, key);
4614
4615string metaPrompt = """"
2955 # Instructions4616 # Instructions
2956 Return a valid schema for the described function.4617 Return a valid schema for the described function.
2957 4618
3076 }4737 }
3077 }4738 }
3078 }4739 }
3079 """4740 """";
3080 .strip();4741ChatCompletionOptions options = new();
3081Map<String, Object> schemaDefinition =4742options.ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat("function-metaschema", BinaryData.FromString("""
3082 Map.of(4743 {
3083 "type", "object",4744 "type": "object",
3084 "properties",4745 "properties": {
3085 Map.of(4746 "name": {
3086 "type",4747 "type": "string",
3087 Map.of(4748 "description": "The name of the function"
3088 "type",4749 },
3089 "string",4750 "description": {
3090 "enum",4751 "type": "string",
3091 List.of("object", "array", "string", "number", "boolean", "null")),4752 "description": "A description of what the function does"
3092 "properties",4753 },
3093 Map.of(4754 "parameters": {
3094 "type",4755 "$ref": "#/$defs/schema_definition",
4756 "description": "A JSON schema that defines the function's parameters"
4757 }
4758 },
4759 "required": [
4760 "name",
4761 "description",
4762 "parameters"
4763 ],
4764 "additionalProperties": false,
4765 "$defs": {
4766 "schema_definition": {
4767 "type": "object",
4768 "properties": {
4769 "type": {
4770 "type": "string",
4771 "enum": [
3095 "object",4772 "object",
3096 "additionalProperties",
3097 Map.of("$ref", "#/$defs/schema_definition")),
3098 "items",
3099 Map.of(
3100 "anyOf",
3101 List.of(
3102 Map.of("$ref", "#/$defs/schema_definition"),
3103 Map.of(
3104 "type",
3105 "array",4773 "array",
3106 "items",
3107 Map.of("$ref", "#/$defs/schema_definition")))),
3108 "required", Map.of("type", "array", "items", Map.of("type", "string")),
3109 "additionalProperties", Map.of("type", "boolean")),
3110 "required", List.of("type"),
3111 "additionalProperties", false,
3112 "if", Map.of("properties", Map.of("type", Map.of("const", "object"))),
3113 "then", Map.of("required", List.of("properties")));
3114Map<String, Object> functionSchema =
3115 Map.of(
3116 "type", "object",
3117 "properties",
3118 Map.of(
3119 "name", Map.of("type", "string", "description", "The name of the function"),
3120 "description",
3121 Map.of(
3122 "type",
3123 "string",4774 "string",
3124 "description",4775 "number",
3125 "A description of what the function does"),4776 "boolean",
3126 "parameters",4777 "null"
3127 Map.of(4778 ]
3128 "$ref",4779 },
3129 "#/$defs/schema_definition",4780 "properties": {
3130 "description",4781 "type": "object",
3131 "A JSON schema that defines the function's parameters")),4782 "additionalProperties": {
3132 "required", List.of("name", "description", "parameters"),4783 "$ref": "#/$defs/schema_definition"
3133 "additionalProperties", false,4784 }
3134 "$defs", Map.of("schema_definition", schemaDefinition));4785 },
3135 4786 "items": {
3136ChatCompletionCreateParams params =4787 "anyOf": [
3137 ChatCompletionCreateParams.builder()4788 {
3138 .model("gpt-5.6-terra")4789 "$ref": "#/$defs/schema_definition"
3139 .addSystemMessage(metaPrompt)4790 },
3140 .addUserMessage("Description:\nSchedule a meeting with a title and start time.")4791 {
3141 .putAdditionalBodyProperty(4792 "type": "array",
3142 "response_format",4793 "items": {
3143 JsonValue.from(4794 "$ref": "#/$defs/schema_definition"
3144 Map.of(4795 }
3145 "type",4796 }
3146 "json_schema",4797 ]
3147 "json_schema",4798 },
3148 Map.of("name", "function-metaschema", "schema", functionSchema))))4799 "required": {
3149 .build();4800 "type": "array",
3150 4801 "items": {
3151client.chat().completions().create(params).choices().stream()4802 "type": "string"
3152 .flatMap(choice -> choice.message().content().stream())4803 }
3153 .forEach(System.out::println);4804 },
4805 "additionalProperties": {
4806 "type": "boolean"
4807 }
4808 },
4809 "required": [
4810 "type"
4811 ],
4812 "additionalProperties": false,
4813 "if": {
4814 "properties": {
4815 "type": {
4816 "const": "object"
4817 }
4818 }
4819 },
4820 "then": {
4821 "required": [
4822 "properties"
4823 ]
4824 }
4825 }
4826 }
4827 }
4828 """));
4829ChatCompletion result = await client.CompleteChatAsync([new SystemChatMessage(metaPrompt), new UserChatMessage("Description: Schedule a meeting with a title and start time.")], options);
4830using JsonDocument parsed = JsonDocument.Parse(result.Content[0].Text);
4831Console.WriteLine(parsed.RootElement);
3154```4832```
3155 4833
3156```ruby4834```ruby