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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aliraza108 opened this issue May 19, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@aliraza108
Copy link

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}}

@aliraza108 aliraza108 added the bug Something isn't working label May 19, 2025
@yusuf-eren
Copy link

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
Copy link
Author

aliraza108 commented May 20, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants