Hi @bi_123,
I would avoid parsing the full rendered UNKNOWN_FIELD_EXCEPTION message. Databricks explicitly notes in the error-handling documentation that the rendered and parameterised messages are not stable across releases, so any logic that depends on a specific phrase being present can break as the wording changes. A more robust approach is to handle the exception using the structured fields exposed by Spark or PySpark, such as getErrorClass(), getSqlState(), and getMessageParameters(), and log those values instead of trying to slice up str(e).
For Auto Loader specifically, the schema inference and evolution documentation explains that when a new column is detected, the stream stops with an UnknownFieldException, but before it fails, Auto Loader updates the schema stored under cloudFiles.schemaLocation. In practice, that means the most useful thing to log for future debugging is usually not the full exception text, but a compact summary that includes the error class, SQLSTATE, message parameters, the stream or query identifiers, the relevant source path if it is available, and the schema location or a schema diff from the latest schema snapshot.
So my recommendation would be to treat the rendered exception text as human-readable context only, ideally truncated, and rely on structured exception metadata plus the schema state in cloudFiles.schemaLocation for anything programmatic. That approach is much more resilient across cases like new fields, type widening, and other schema changes, and it keeps the logs focused on the details that are actually useful when someone needs to debug the issue later. The same Auto Loader documentation also covers the different schema evolution modes, including addNewColumns, addNewColumnsWithTypeWidening, and rescue, which is another reason not to assume a single message shape will always apply across every schema change scenario.
If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.
Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***