Format validation
We can perform a variety of error checks to validate that each conversation in the dataset adheres to the format expected by the fine-tuning API. Errors are categorized based on their nature for easier debugging. Data Type Check: Checks whether each entry in the dataset is a dictionary (dict). Error type: data_type. Presence of Message List: Checks if a messages list is present in each entry. Error type: missing_messages_list. Message Keys Check: Validates that each message in the messages list contains the keys role and content. Error type: message_missing_key. Unrecognized Keys in Messages: Logs if a message has keys other than role, content, and name. Error type: message_unrecognized_key. Role Validation: Ensures the role is one of "system", "user", or "assistant". Error type: unrecognized_role. Content Validation: Verifies that content has textual data and is a string. Error type: missing_content. Assistant Message Presence: Checks that each conversation has at least one message from the assistant. Error type: example_missing_assistant_message. The code below performs these checks, and outputs counts for each type of error found are printed. This is useful for debugging and ensuring the dataset is ready for the next steps.