def METHOD_NAME(router: APIRouter):
    QueryType = Union[TextClassificationQuery, TokenClassificationQuery, Text2TextQuery]
    class DeleteRecordsResponse(BaseModel):
        matched: int
        processed: int
    RecordType = Union[
        TextClassificationRecord,
        TokenClassificationRecord,
        Text2TextRecord,
    ]
    @router.get("/{name}/records/{id}", response_model=RecordType)
    async def get_dataset_record(
        name: str,
        id: str,
        request_deps: CommonTaskHandlerDependencies = Depends(),
        service: DatasetsService = Depends(DatasetsService.get_instance),
        search: SearchRecordsService = Depends(SearchRecordsService.get_instance),
        current_user: User = Security(auth.get_current_user),
    ) -> RecordType:
        found = await service.find_by_name(
            user=current_user,
            name=name,
            workspace=request_deps.workspace,
        )
        record_class = TasksFactory.get_task_record(found.task)
        return await search.find_record_by_id(
            dataset=found,
            id=id,
            record_type=record_class,
        )
    @router.delete(
        "/{name}/data",
        operation_id="delete_dataset_records",
        response_model=DeleteRecordsResponse,
    )
    async def delete_dataset_records(
        name: str,
        query: Optional[QueryType] = None,
        mark_as_discarded: bool = Query(
            default=False,
            title="If True, matched records won't be deleted."
            " Instead of that, the record status will be changed to `Discarded`",
        ),
        request_deps: CommonTaskHandlerDependencies = Depends(),
        service: DatasetsService = Depends(DatasetsService.get_instance),
        storage: RecordsStorageService = Depends(RecordsStorageService.get_instance),
        current_user: User = Security(auth.get_current_user),
    ):
        found = await service.find_by_name(
            user=current_user,
            name=name,
            workspace=request_deps.workspace,
        )
        result = await storage.delete_records(
            user=current_user,
            dataset=found,
            query=query,
            mark_as_discarded=mark_as_discarded,
        )
        return DeleteRecordsResponse(
            matched=result.processed,
            processed=result.deleted or result.discarded,
        )