I'm sorry, here's the same code with better formatting:
```pascal
program NamedPipeExample;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  PIPE_NAME = '\.\pipe\MyNamedPipe';

var
  hPipe: THandle;
  lpvMessage: PChar;
  cbRead, cbWritten: DWORD;
begin
  try
    // Create a named pipe
    hPipe := CreateNamedPipe(PIPE_NAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES, 512, 512, 0, nil);

    if hPipe = INVALID_HANDLE_VALUE then
    begin
      raise Exception.Create('Failed to create named pipe: ' + SysErrorMessage(GetLastError));
    end;

    // Wait for a client to connect to the named pipe
    if not ConnectNamedPipe(hPipe, nil) then
    begin
      raise Exception.Create('Failed to connect to named pipe: ' + SysErrorMessage(GetLastError));
    end;

    // Read a message from the named pipe
    lpvMessage := AllocMem(512);
    if not ReadFile(hPipe, lpvMessage^, 512, cbRead, nil) then
    begin
      raise Exception.Create('Failed to read message from named pipe: ' + SysErrorMessage(GetLastError));
    end;
    WriteLn('Received message: ' + string(lpvMessage));
  
    // Write a response to the named pipe
    if not WriteFile(hPipe, 'Hello from Delphi!', 19, cbWritten, nil) then
    begin
      raise Exception.Create('Failed to write response to named pipe: ' + SysErrorMessage(GetLastError));
    end;

    // Disconnect from the named pipe
    DisconnectNamedPipe(hPipe);
    CloseHandle(hPipe);

  except
    on E: Exception do
    begin
      WriteLn(E.Message);
    end;
  end;
end.
```
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence