Skip to content

Commit a7112f4

Browse files
of course there was an easier way to do this
1 parent b49cd81 commit a7112f4

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

docs/models/openai.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,13 @@ condition: column ("=" | ">" | "<") (NUMBER | STRING)
255255
%import common.WS
256256
%ignore WS
257257
''' # (1)!
258-
def database_query(sql: str) -> str:
259-
return sql # (2)!
260258

261-
output_tool = ToolOutput(database_query, text_format=FunctionTextFormat(syntax='lark', grammar=sql_grammar_definition))
259+
output_tool = ToolOutput(str, text_format=FunctionTextFormat(syntax='lark', grammar=sql_grammar_definition))
262260
model = OpenAIResponsesModel('gpt-5')
263261
agent = Agent(model, output_type=output_tool)
264262
```
265263

266264
1. An inline SQL grammar definition would be quite extensive and so this simplified version has been written, you can find an example SQL grammar [in the openai example](https://cookbook.openai.com/examples/gpt-5/gpt-5_new_params_and_tools#33-example---sql-dialect--ms-sql-vs-postgresql). There are also example grammars in the [lark repo](https://github.com/lark-parser/lark/blob/master/examples/composition/json.lark). Remember that a simpler grammar that matches your DDL will be easier for GPT-5 to work with and will result in fewer semantically invalid results.
267-
2. Returning the input directly might seem odd, remember that it has been constrained to the provided grammar. This can be useful if you want GPT-5 to generate content according to a grammar that you then use extensively through your program.
268265

269266
##### Best Practices
270267

0 commit comments

Comments
 (0)