Skip to content

calling as_dict() on default instantiated Attempt now doesn't raise TypeError#1590

Merged
erickgalinkin merged 2 commits intoNVIDIA:mainfrom
leondz:bugfix/attempt_default_prompt_asdict
Feb 2, 2026
Merged

calling as_dict() on default instantiated Attempt now doesn't raise TypeError#1590
erickgalinkin merged 2 commits intoNVIDIA:mainfrom
leondz:bugfix/attempt_default_prompt_asdict

Conversation

@leondz
Copy link
Collaborator

@leondz leondz commented Feb 2, 2026

before this PR:

>>> from garak.attempt import Attempt
>>> a = Attempt()
>>> a.as_dict()
Traceback (most recent call last):
  File "<python-input-8>", line 1, in <module>
    a.as_dict()
    ~~~~~~~~~^^
  File "/home/lderczynski/dev/garacc/garak/attempt.py", line 268, in as_dict
    "prompt": asdict(self.prompt),
              ~~~~~~^^^^^^^^^^^^^
  File "/home/lderczynski/anaconda3/envs/garak/lib/python3.13/dataclasses.py", line 1358, in asdict
    raise TypeError("asdict() should be called on dataclass instances")
TypeError: asdict() should be called on dataclass instances

PR has Attempt.as_dict() only call dataclass.asdict() on Attempt.prompt if Attempt.prompt is not None

after:

>>> from garak.attempt import Attempt
>>> a = Attempt()
>>> a.as_dict()
{'entry_type': 'attempt', 'uuid': '51c21869-ab75-4b7a-9f59-8511a6039189', 'seq': -1, 'status': 0, 'probe_classname': None, 'probe_params': {}, 'targets': [], 'prompt': None, 'outputs': [], 'detector_results': {}, 'notes': {}, 'goal': None, 'conversations': [{'turns': [], 'notes': {}}], 'reverse_translation_outputs': []}

PR also adds test that instantiates an Attempt and calls its as_dict()

@leondz leondz added the bug Something isn't working label Feb 2, 2026
@leondz leondz marked this pull request as draft February 2, 2026 14:18
Copy link
Collaborator

@jmartin-tech jmartin-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@leondz leondz marked this pull request as ready for review February 2, 2026 15:58
@leondz leondz requested a review from aishwaryap February 2, 2026 16:03
Copy link
Collaborator

@erickgalinkin erickgalinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cough I like it.

@erickgalinkin erickgalinkin merged commit a6a6c14 into NVIDIA:main Feb 2, 2026
16 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants