Skip to content

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid request: prompt is empty or malformed.', 'type': 'invalid_request_error', 'param': None, 'code': None}} #716

Open
@aliraza108

Description

@aliraza108

from openai import OpenAI
from openai.agent import Agent

client = OpenAI(api_key="sk-...") # Use your key here

Define a simple agent (no tools used)

agent = Agent(
name="TestAgent",
instructions="Answer questions as helpfully as possible.",
)

Try running the agent with an empty string (or malformed query)

response = agent.run("")
print(response)

OUTPUT:
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid request: prompt is empty or malformed.', 'type': 'invalid_request_error', 'param': None, 'code': None}}

Activity

yusuf-eren

yusuf-eren commented on May 19, 2025

@yusuf-eren

Hi @aliraza108 , I tried to reproduce the bug but couldn't get the same response.

Here is my full code;

import asyncio
from agents import Agent, Runner

async def main():
    agent = Agent(
        name="TestAgent",
        instructions="Answer questions as helpfully as possible.",
    )

    result = await Runner.run(agent, "")
    print(result)


if __name__ == "__main__":
    asyncio.run(main())

Output:

(.venv) yusuferen@Yusufs-MacBook-Pro openai-agents-python % python examples/basic/test.py
RunResult:
- Last agent: Agent(name="TestAgent", ...)
- Final output (str):
    Hello! How can I assist you today?
- 1 new item(s)
- 1 raw response(s)
- 0 input guardrail result(s)
- 0 output guardrail result(s)
(See `RunResult` for more details)

Which version do you use? And how you ran the file?

aliraza108

aliraza108 commented on May 20, 2025

@aliraza108
Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yusuf-eren@aliraza108

        Issue actions

          openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid request: prompt is empty or malformed.', 'type': 'invalid_request_error', 'param': None, 'code': None}} · Issue #716 · openai/openai-agents-python