Skip to content

TypeError: Object of type PosixPath is not JSON serializable when saving benchmark report with --output-dir #781

Description

@gdevenyi

Description

When running guidellm benchmark run with --output-dir and --outputs json, the benchmark completes successfully but crashes during report serialization:

TypeError: Object of type PosixPath is not JSON serializable

Root Cause

In src/guidellm/benchmark/schemas/generative/report.py:105, save_file() calls:

model_dict = self.model_dump()       # mode='python' (default)
save_str = json.dumps(model_dict)     # TypeError

model_dump() defaults to mode='python', which preserves PosixPath objects. While BenchmarkGenerativeTextArgs has a @field_serializer("output_dir") that converts Path → str, that serializer only activates during model_dump_json() or model_dump(mode='json'), not the default model_dump().

The PosixPath originates from --output-dir, which click produces via click.Path(path_type=Path).

Reproduction

guidellm benchmark run \
  --target "http://localhost:8000" \
  --profile "kind=sweep" \
  --data '{"kind": "json_file", "path": "sharegpt_flat.jsonl", "load_kwargs": {"split": "train"}}' \
  --max-seconds 60 \
  --max-requests 5000 \
  --output-dir ./benchmark_results \
  --outputs json,csv,html

Stack Trace

File "guidellm/benchmark/outputs/serialized.py", line 82, in finalize
    return report.save_file(output_path)
File "guidellm/benchmark/schemas/generative/report.py", line 106, in save_file
    save_str = json.dumps(model_dict)
File "json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
TypeError: Object of type PosixPath is not JSON serializable

Suggested Fix

Change report.py:105 to use JSON serialization mode:

model_dict = self.model_dump(mode='json')

This one-word change activates @field_serializer decorators and converts Path → str before json.dumps() sees it. The same fix should be applied to the YAML branch on line 108 as well.

Environment:

  • guidellm version: latest (installed via pip)
  • Python 3.12
  • Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRepresents a user-visible defectescapeA problem found by an external user in a GuideLLM release.good first issueGood for newcomerspriority-high

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions