How to fully suppress sensitive tool invocation parameters in OpenAI Agents SDK event streams?

Hi everyone,

I’m working with the open-source openai-agents-python SDK, streaming events (RunItemStreamEvent, RawResponsesStreamEvent) from an agent runner to a frontend via Server-Sent Events (SSE) and ND-JSON.

Context:

Our current setup (agents_ndjson.py) transforms SDK events to ND-JSON and filters out sensitive internal messages before sending them to the frontend. Typically, the flow is:

  1. The LLM outputs a message containing a tool invocation, e.g.:

json

CopyEdit

{"pdf_url":"https://…","lang":"spa"}
  1. SDK emits RunItemStreamEvent(name="message_output_created").
  2. The tool runs, and on completion, the SDK emits RunItemStreamEvent(name="tool_output").

The problem:

Despite our filtering logic, sensitive initial invocation messages (with URLs or parameters) still reach the frontend briefly before being filtered out. We believe this leakage is due to incremental delta events (RawResponsesStreamEvent) being emitted before our filters have context.

What we’ve tried:

  • Filtering events explicitly at both message_output_created and RawResponsesStreamEvent levels.
  • Regex-based filtering on internal keys (e.g., pdf_url, file_url, etc.).
  • Attempting to remove or delay events containing sensitive info before they reach the frontend.

However, sensitive messages still occasionally leak through.

Our questions:

  • Where is the exact best place to reliably intercept and fully suppress sensitive messages without disrupting the event stream?
  • Is there a robust pattern or recommended strategy for reliably identifying and filtering internal tool calls emitted as incremental delta events?
  • Would buffering events until we have enough context to decide their sensitivity be the best solution? Any potential pitfalls?

Has anyone faced similar challenges? Any guidance, suggestions, or alternative approaches would be greatly appreciated!

Thanks!

An example of JSON I receive on the frontend:

{“input”:“JUZGADO DE1RA INSTANCIA EN LO PENAL CONTRAVENCIONAL Y FALTAS N°26\nURDAPILLE, PEDRO VICENTE SOBRE - INCUMPLIMIENTO LOSBERES ASISTENCIAAMILARNúmero122016/202UI J0017Actación8237725Ciudad de Buenos Aires mayo.\AUT Para resolver en la presente causa nro caratulada “” que tramita por ante esteuzgado lo Penal Contravencional yaltas mi cargo Secretaría51 sobre posible declaración extinción acciónSIDANDO Que el abril4 sevió suspender proceso prueba término doce () meses imponiendo al Sr Pedro Vicente Urdapleta titular del DNI29039191 cumplimiento las siguientes reglas conductaij residencia someter cuidado Oficina Control Suspensión Juicio Pr; Cum citaciones Fiscalía o le hicieren Realizar tallerResponsabilidadental Programa Asistencia Vinc”, dict Ministerio Público Defensa Mantener un trato cordial respetuoso denunciante María Dolores Méez…” informe final elaborado órgano control da cuenta pautuestas obra Registro Nacional despr no registra nuevos antecedentes penales vista evacu consider registrar imput haberido establecidas correspond tener suspensión extinguir Ahora bien teniendo fecha oper plazo entend dió atención informado sum manifest Dra Claudia Bar corresponde aplicar especie previsto art76 ter quinto párrafo Código consecuencia declarar favorando los términos218 fine CPPCABA Finalmente virtud temperamento adopt imposición costas Por todo ello RESUELVO DECL LA EXTCIÓN ACC demás condicionesantes momento establecer según indicadoandos). IISE orden delito objeto SIN COST arts354355 Notíqu partes lí oficio archív sin más trámite”}