async def _process_table_batch(
        self, schema: str, table: str, entity_class: Type[PolymorphicEntity], batch: List
    ) -> AsyncGenerator[ChunkEntity, None]:
        """Process a batch of records from a table."""
        for record in batch:
            data = dict(record)

            # Simply try to convert all strings to JSON
            for key, value in data.items():
                if isinstance(value, str):
                    try:
                        parsed_value = json.loads(value)
                        data[key] = parsed_value
                    except (json.JSONDecodeError, ValueError):
                        # Keep as string if not valid JSON
                        pass

            model_fields = entity_class.model_fields
            primary_keys = model_fields["primary_key_columns"].default_factory()
            pk_values = [str(data[pk]) for pk in primary_keys]
            entity_id = f"{schema}.{table}:" + ":".join(pk_values)

            # Convert field values to match expected types in the entity model
            processed_data = await self._convert_field_values(data, model_fields)

            yield entity_class(entity_id=entity_id, **processed_data)
Process a batch of records from a table.
backend/airweave/platform/sources/postgresql.py