Skip to content

ValidationError: "String should have at least 1 character" occurs in Copilot Studio Python Client when Activity.text is empty #48

@runceel

Description

@runceel

Overview

When running the sample in Agents-for-python/test_samples/copilot_studio_client_sample, a pydantic_core._pydantic_core.ValidationError is raised if the Activity.text field is an empty string. This causes the application to crash.

Error Details

pydantic_core._pydantic_core.ValidationError: 1 validation error for Activity
text
  String should have at least 1 character [type=string_too_short, input_value='', input_type=str]

Steps to Reproduce

  1. Install all required dependencies.
  2. Prepare a .env file with valid authentication information.
  3. Run the following command in the terminal:
    python app.py
    
  4. Start a chat and enter a message.
  5. The above error occurs if an empty string is passed to Activity.text.

Expected Behavior

The SDK should gracefully handle cases where Activity.text is empty, and the application should not crash due to a validation error.

Environment

  • OS: Windows 11
  • Python: 3.13.3
  • Copilot Studio Client SDK: 0.0.0a3

Additional Information

  • This issue is similar to Agents-for-js #325, where a Zod validation error occurs in the JavaScript SDK for the same reason.
  • The .NET SDK does not have this problem.
  • In the Python SDK, if Activity.text is empty or missing, a validation error is raised and the application stops.
  • Relevant code excerpt from app.py:
    loop.run_until_complete(
        ChatConsoleService(create_mcs_client(mcs_connection_settings)).start_service()
    )
  • Please see the attached logs and stack trace for more details.
Traceback (most recent call last):
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\app.py", line 58, in <module>
    loop.run_until_complete(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        ChatConsoleService(create_mcs_client(mcs_connection_settings)).start_service()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 719, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\chat_console_service.py", line 27, in start_service
    async for activity in self._copilot_client.ask_question(question):
        self._print_activity(activity)
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\venv\Lib\site-packages\microsoft\agents\copilotstudio\client\copilot_client.py", line 78, in ask_question
    async for activity in self.ask_question_with_activity(activity):
        yield activity
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\venv\Lib\site-packages\microsoft\agents\copilotstudio\client\copilot_client.py", line 105, in ask_question_with_activity
    async for activity in self.post_request(url, data, headers):
        yield activity
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\venv\Lib\sitio\client\copilot_client.py", line 44, in post_request
  File "D:\Repos\microsoft\Agents-for-python\test_samples\copilot_studio_client_sample\venv\Lib\site-packages\pydantic\main.py", line 746, in model_validate_json
    return cls.__pydantic_validator__.validate_json(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        json_data, strict=strict, context=context, by_alias=by_name
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Activity
text
  String should have at least 1 character [type=string_too_short, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/string_too_short

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions