From ec4e4a15dc2470f4e8b0da1ded870b52b28cd331 Mon Sep 17 00:00:00 2001
From: Viicos <65306057+Viicos@users.noreply.github.com>
Date: Fri, 7 Feb 2025 16:11:59 +0100
Subject: [PATCH] Rename validation and serialization schema types to be unique

`validator-` or `serializer-` is prepended, and the existing
ones are deprecated.
---
 python/pydantic_core/core_schema.py           | 40 ++++++++---------
 src/serializers/shared.rs                     | 45 ++++++++++++++++---
 src/serializers/type_serializers/function.rs  | 12 ++---
 src/validators/function.rs                    | 18 +++++---
 src/validators/mod.rs                         | 30 ++++++++++++-
 tests/benchmarks/complete_schema.py           |  8 ++--
 tests/benchmarks/test_micro_benchmarks.py     |  6 +--
 tests/test.rs                                 |  4 +-
 tests/test_errors.py                          |  2 +-
 tests/test_misc.py                            | 33 ++++++++++++++
 tests/test_schema_functions.py                | 14 ++++--
 tests/test_typing.py                          |  2 +-
 tests/validators/test_chain.py                | 11 +++--
 .../validators/test_definitions_recursive.py  |  2 +-
 tests/validators/test_function.py             | 26 ++++++-----
 tests/validators/test_model.py                |  2 +-
 tests/validators/test_model_fields.py         |  6 +--
 tests/validators/test_model_init.py           |  6 +--
 tests/validators/test_typed_dict.py           |  2 +-
 19 files changed, 190 insertions(+), 79 deletions(-)

diff --git a/python/pydantic_core/core_schema.py b/python/pydantic_core/core_schema.py
index c477bae1d..354a93466 100644
--- a/python/pydantic_core/core_schema.py
+++ b/python/pydantic_core/core_schema.py
@@ -261,7 +261,7 @@ def simple_ser_schema(type: ExpectedSerializationTypes) -> SimpleSerSchema:
 
 
 class PlainSerializerFunctionSerSchema(TypedDict, total=False):
-    type: Required[Literal['function-plain']]
+    type: Required[Literal['serializer-function-plain']]
     function: Required[SerializerFunction]
     is_field_serializer: bool  # default False
     info_arg: bool  # default False
@@ -292,7 +292,7 @@ def plain_serializer_function_ser_schema(
         # just to avoid extra elements in schema, and to use the actual default defined in rust
         when_used = None  # type: ignore
     return _dict_not_none(
-        type='function-plain',
+        type='serializer-function-plain',
         function=function,
         is_field_serializer=is_field_serializer,
         info_arg=info_arg,
@@ -322,7 +322,7 @@ def __call__(self, input_value: Any, index_key: int | str | None = None, /) -> A
 
 
 class WrapSerializerFunctionSerSchema(TypedDict, total=False):
-    type: Required[Literal['function-wrap']]
+    type: Required[Literal['serializer-function-wrap']]
     function: Required[WrapSerializerFunction]
     is_field_serializer: bool  # default False
     info_arg: bool  # default False
@@ -356,7 +356,7 @@ def wrap_serializer_function_ser_schema(
         # just to avoid extra elements in schema, and to use the actual default defined in rust
         when_used = None  # type: ignore
     return _dict_not_none(
-        type='function-wrap',
+        type='serializer-function-wrap',
         function=function,
         is_field_serializer=is_field_serializer,
         info_arg=info_arg,
@@ -1966,7 +1966,7 @@ class _ValidatorFunctionSchema(TypedDict, total=False):
 
 
 class BeforeValidatorFunctionSchema(_ValidatorFunctionSchema, total=False):
-    type: Required[Literal['function-before']]
+    type: Required[Literal['validator-function-before']]
     json_schema_input_schema: CoreSchema
 
 
@@ -2006,7 +2006,7 @@ def fn(v: bytes) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-before',
+        type='validator-function-before',
         function={'type': 'no-info', 'function': function},
         schema=schema,
         ref=ref,
@@ -2057,7 +2057,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-before',
+        type='validator-function-before',
         function=_dict_not_none(type='with-info', function=function, field_name=field_name),
         schema=schema,
         ref=ref,
@@ -2068,7 +2068,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
 
 
 class AfterValidatorFunctionSchema(_ValidatorFunctionSchema, total=False):
-    type: Required[Literal['function-after']]
+    type: Required[Literal['validator-function-after']]
 
 
 def no_info_after_validator_function(
@@ -2105,7 +2105,7 @@ def fn(v: str) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-after',
+        type='validator-function-after',
         function={'type': 'no-info', 'function': function},
         schema=schema,
         ref=ref,
@@ -2154,7 +2154,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-after',
+        type='validator-function-after',
         function=_dict_not_none(type='with-info', function=function, field_name=field_name),
         schema=schema,
         ref=ref,
@@ -2191,7 +2191,7 @@ class WithInfoWrapValidatorFunctionSchema(TypedDict, total=False):
 
 
 class WrapValidatorFunctionSchema(TypedDict, total=False):
-    type: Required[Literal['function-wrap']]
+    type: Required[Literal['validator-function-wrap']]
     function: Required[WrapValidatorFunction]
     schema: Required[CoreSchema]
     ref: str
@@ -2239,7 +2239,7 @@ def fn(
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-wrap',
+        type='validator-function-wrap',
         function={'type': 'no-info', 'function': function},
         schema=schema,
         json_schema_input_schema=json_schema_input_schema,
@@ -2291,7 +2291,7 @@ def fn(
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-wrap',
+        type='validator-function-wrap',
         function=_dict_not_none(type='with-info', function=function, field_name=field_name),
         schema=schema,
         json_schema_input_schema=json_schema_input_schema,
@@ -2302,7 +2302,7 @@ def fn(
 
 
 class PlainValidatorFunctionSchema(TypedDict, total=False):
-    type: Required[Literal['function-plain']]
+    type: Required[Literal['validator-function-plain']]
     function: Required[ValidationFunction]
     ref: str
     json_schema_input_schema: CoreSchema
@@ -2341,7 +2341,7 @@ def fn(v: str) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-plain',
+        type='validator-function-plain',
         function={'type': 'no-info', 'function': function},
         ref=ref,
         json_schema_input_schema=json_schema_input_schema,
@@ -2383,7 +2383,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
         serialization: Custom serialization schema
     """
     return _dict_not_none(
-        type='function-plain',
+        type='validator-function-plain',
         function=_dict_not_none(type='with-info', function=function, field_name=field_name),
         ref=ref,
         json_schema_input_schema=json_schema_input_schema,
@@ -3965,10 +3965,10 @@ def definition_reference_schema(
     'frozenset',
     'generator',
     'dict',
-    'function-after',
-    'function-before',
-    'function-wrap',
-    'function-plain',
+    'validator-function-after',
+    'validator-function-before',
+    'validator-function-wrap',
+    'validator-function-plain',
     'default',
     'nullable',
     'union',
diff --git a/src/serializers/shared.rs b/src/serializers/shared.rs
index f7a018749..1563fb8f0 100644
--- a/src/serializers/shared.rs
+++ b/src/serializers/shared.rs
@@ -1,4 +1,5 @@
 use std::borrow::Cow;
+use std::ffi::CString;
 use std::fmt::Debug;
 
 use pyo3::exceptions::PyTypeError;
@@ -148,6 +149,29 @@ combined_serializer! {
     }
 }
 
+fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
+    let maybe_new_type = match type_ {
+        "function-plain" => Some("serializer-function-plain"),
+        "function-wrap" => Some("serializer-function-wrap"),
+        _ => None,
+    };
+
+    match maybe_new_type {
+        Some(new_type) => {
+            let deprecation_message =
+                format!("Serialization core schema type '{type_}' is deprecated, use '{new_type}'");
+            let _ = PyErr::warn(
+                py,
+                &py.get_type::<pyo3::exceptions::PyDeprecationWarning>(),
+                &CString::new(deprecation_message)?,
+                1,
+            );
+            Ok(new_type.to_owned())
+        }
+        None => Ok(type_.to_owned()),
+    }
+}
+
 impl CombinedSerializer {
     fn _build(
         schema: &Bound<'_, PyDict>,
@@ -159,9 +183,12 @@ impl CombinedSerializer {
 
         if let Some(ser_schema) = schema.get_as::<Bound<'_, PyDict>>(intern!(py, "serialization"))? {
             let op_ser_type: Option<Bound<'_, PyString>> = ser_schema.get_as(type_key)?;
-            match op_ser_type.as_ref().map(|py_str| py_str.to_str()).transpose()? {
-                Some("function-plain") => {
-                    // `function-plain` is a special case, not included in `find_serializer` since it means
+            let op_ser_type = op_ser_type.as_ref().map(|py_str| py_str.to_str()).transpose()?;
+            let new_type = op_ser_type.map(|typ| get_new_type(schema.py(), typ).unwrap());
+
+            match new_type.as_deref() {
+                Some("serializer-function-plain") => {
+                    // `serializer-function-plain` is a special case, not included in `find_serializer` since it means
                     // something different in `schema.type`
                     // NOTE! we use the `schema` here, not `ser_schema`
                     return super::type_serializers::function::FunctionPlainSerializer::build(
@@ -169,10 +196,12 @@ impl CombinedSerializer {
                         config,
                         definitions,
                     )
-                    .map_err(|err| py_schema_error_type!("Error building `function-plain` serializer:\n  {}", err));
+                    .map_err(|err| {
+                        py_schema_error_type!("Error building `serializer-function-plain` serializer:\n  {}", err)
+                    });
                 }
-                Some("function-wrap") => {
-                    // `function-wrap` is also a special case, not included in `find_serializer` since it mean
+                Some("serializer-function-wrap") => {
+                    // `serializer-function-wrap` is also a special case, not included in `find_serializer` since it mean
                     // something different in `schema.type`
                     // NOTE! we use the `schema` here, not `ser_schema`
                     return super::type_serializers::function::FunctionWrapSerializer::build(
@@ -180,7 +209,9 @@ impl CombinedSerializer {
                         config,
                         definitions,
                     )
-                    .map_err(|err| py_schema_error_type!("Error building `function-wrap` serializer:\n  {}", err));
+                    .map_err(|err| {
+                        py_schema_error_type!("Error building `serializer-function-wrap` serializer:\n  {}", err)
+                    });
                 }
                 // applies to lists tuples and dicts, does not override the main schema `type`
                 Some("include-exclude-sequence" | "include-exclude-dict") => (),
diff --git a/src/serializers/type_serializers/function.rs b/src/serializers/type_serializers/function.rs
index 3aac20d7c..e90b63b87 100644
--- a/src/serializers/type_serializers/function.rs
+++ b/src/serializers/type_serializers/function.rs
@@ -62,7 +62,7 @@ impl BuildSerializer for FunctionAfterSerializerBuilder {
 pub struct FunctionPlainSerializerBuilder;
 
 impl BuildSerializer for FunctionPlainSerializerBuilder {
-    const EXPECTED_TYPE: &'static str = "function-plain";
+    const EXPECTED_TYPE: &'static str = "serializer-function-plain";
     fn build(
         schema: &Bound<'_, PyDict>,
         config: Option<&Bound<'_, PyDict>>,
@@ -95,7 +95,7 @@ fn destructure_function_schema<'py>(schema: &Bound<'py, PyDict>) -> PyResult<(bo
 }
 
 impl BuildSerializer for FunctionPlainSerializer {
-    const EXPECTED_TYPE: &'static str = "function-plain";
+    const EXPECTED_TYPE: &'static str = "serializer-function-plain";
 
     /// NOTE! `schema` here is the actual `CoreSchema`, not `schema.serialization` as in the other builders
     /// (done this way to match `FunctionWrapSerializer` which requires the full schema)
@@ -125,7 +125,7 @@ impl BuildSerializer for FunctionPlainSerializer {
             }
         };
 
-        let name = format!("plain_function[{function_name}]");
+        let name = format!("serializer-function-plain[{function_name}]");
         Ok(Self {
             func: function.unbind(),
             function_name,
@@ -310,7 +310,7 @@ fn copy_outer_schema<'py>(schema: &Bound<'py, PyDict>) -> PyResult<Bound<'py, Py
 pub struct FunctionWrapSerializerBuilder;
 
 impl BuildSerializer for FunctionWrapSerializerBuilder {
-    const EXPECTED_TYPE: &'static str = "function-wrap";
+    const EXPECTED_TYPE: &'static str = "serializer-function-wrap";
     fn build(
         schema: &Bound<'_, PyDict>,
         config: Option<&Bound<'_, PyDict>>,
@@ -339,7 +339,7 @@ pub struct FunctionWrapSerializer {
 }
 
 impl BuildSerializer for FunctionWrapSerializer {
-    const EXPECTED_TYPE: &'static str = "function-wrap";
+    const EXPECTED_TYPE: &'static str = "serializer-function-wrap";
 
     /// NOTE! `schema` here is the actual `CoreSchema`, not `schema.serialization` as in the other builders
     /// (done this way since we need the `CoreSchema`)
@@ -368,7 +368,7 @@ impl BuildSerializer for FunctionWrapSerializer {
             None => AnySerializer::build(schema, config, definitions)?,
         };
 
-        let name = format!("wrap_function[{function_name}, {}]", serializer.get_name());
+        let name = format!("serializer-function-wrap[{function_name}, {}]", serializer.get_name());
         Ok(Self {
             serializer: Arc::new(serializer),
             func: function.into(),
diff --git a/src/validators/function.rs b/src/validators/function.rs
index 6f0eea7f4..513ec812d 100644
--- a/src/validators/function.rs
+++ b/src/validators/function.rs
@@ -89,7 +89,7 @@ pub struct FunctionBeforeValidator {
     info_arg: bool,
 }
 
-impl_build!(FunctionBeforeValidator, "function-before");
+impl_build!(FunctionBeforeValidator, "validator-function-before");
 
 impl FunctionBeforeValidator {
     fn _validate<'s, 'py>(
@@ -157,7 +157,7 @@ pub struct FunctionAfterValidator {
     info_arg: bool,
 }
 
-impl_build!(FunctionAfterValidator, "function-after");
+impl_build!(FunctionAfterValidator, "validator-function-after");
 
 impl FunctionAfterValidator {
     fn _validate<'py, I: Input<'py> + ?Sized>(
@@ -225,7 +225,7 @@ pub struct FunctionPlainValidator {
 }
 
 impl BuildValidator for FunctionPlainValidator {
-    const EXPECTED_TYPE: &'static str = "function-plain";
+    const EXPECTED_TYPE: &'static str = "validator-function-plain";
 
     fn build(
         schema: &Bound<'_, PyDict>,
@@ -240,7 +240,10 @@ impl BuildValidator for FunctionPlainValidator {
                 Some(c) => c.clone().into(),
                 None => py.None(),
             },
-            name: format!("function-plain[{}()]", function_name(function_info.function.bind(py))?),
+            name: format!(
+                "validator-function-plain[{}()]",
+                function_name(function_info.function.bind(py))?
+            ),
             field_name: function_info.field_name.clone(),
             info_arg: function_info.info_arg,
         }
@@ -284,7 +287,7 @@ pub struct FunctionWrapValidator {
 }
 
 impl BuildValidator for FunctionWrapValidator {
-    const EXPECTED_TYPE: &'static str = "function-wrap";
+    const EXPECTED_TYPE: &'static str = "validator-function-wrap";
 
     fn build(
         schema: &Bound<'_, PyDict>,
@@ -303,7 +306,10 @@ impl BuildValidator for FunctionWrapValidator {
                 Some(c) => c.clone().into(),
                 None => py.None(),
             },
-            name: format!("function-wrap[{}()]", function_name(function_info.function.bind(py))?),
+            name: format!(
+                "validator-function-wrap[{}()]",
+                function_name(function_info.function.bind(py))?
+            ),
             field_name: function_info.field_name.clone(),
             info_arg: function_info.info_arg,
             hide_input_in_errors,
diff --git a/src/validators/mod.rs b/src/validators/mod.rs
index 75f39df29..a63eb941c 100644
--- a/src/validators/mod.rs
+++ b/src/validators/mod.rs
@@ -1,3 +1,4 @@
+use std::ffi::CString;
 use std::fmt::Debug;
 
 use enum_dispatch::enum_dispatch;
@@ -510,6 +511,30 @@ macro_rules! validator_match {
     };
 }
 
+fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
+    let maybe_new_type = match type_ {
+        "function-before" => Some("validator-function-before"),
+        "function-after" => Some("validator-function-after"),
+        "function-plain" => Some("validator-function-plain"),
+        "function-wrap" => Some("validator-function-wrap"),
+        _ => None,
+    };
+
+    match maybe_new_type {
+        Some(new_type) => {
+            let deprecation_message = format!("Core schema type '{type_}' is deprecated, use '{new_type}'");
+            let _ = PyErr::warn(
+                py,
+                &py.get_type::<pyo3::exceptions::PyDeprecationWarning>(),
+                &CString::new(deprecation_message)?,
+                1,
+            );
+            Ok(new_type.to_owned())
+        }
+        None => Ok(type_.to_owned()),
+    }
+}
+
 pub fn build_validator(
     schema: &Bound<'_, PyAny>,
     config: Option<&Bound<'_, PyDict>>,
@@ -525,8 +550,11 @@ pub fn build_validator(
         return Ok(prebuilt_validator);
     }
 
+    let new_type = get_new_type(schema.py(), type_)?;
+    let new_type_str = new_type.as_str();
+
     validator_match!(
-        type_,
+        new_type_str,
         dict,
         config,
         definitions,
diff --git a/tests/benchmarks/complete_schema.py b/tests/benchmarks/complete_schema.py
index e12cdb298..a8960559c 100644
--- a/tests/benchmarks/complete_schema.py
+++ b/tests/benchmarks/complete_schema.py
@@ -161,7 +161,7 @@ def wrap_function(input_value, validator, info):
                             'field_before': {
                                 'type': 'typed-dict-field',
                                 'schema': {
-                                    'type': 'function-before',
+                                    'type': 'validator-function-before',
                                     'function': {'type': 'with-info', 'function': append_func},
                                     'schema': {'type': 'str'},
                                 },
@@ -169,7 +169,7 @@ def wrap_function(input_value, validator, info):
                             'field_after': {
                                 'type': 'typed-dict-field',
                                 'schema': {
-                                    'type': 'function-after',
+                                    'type': 'validator-function-after',
                                     'function': {'type': 'with-info', 'function': append_func},
                                     'schema': {'type': 'str'},
                                 },
@@ -177,7 +177,7 @@ def wrap_function(input_value, validator, info):
                             'field_wrap': {
                                 'type': 'typed-dict-field',
                                 'schema': {
-                                    'type': 'function-wrap',
+                                    'type': 'validator-function-wrap',
                                     'function': {'type': 'with-info', 'function': wrap_function},
                                     'schema': {'type': 'str'},
                                 },
@@ -185,7 +185,7 @@ def wrap_function(input_value, validator, info):
                             'field_plain': {
                                 'type': 'typed-dict-field',
                                 'schema': {
-                                    'type': 'function-plain',
+                                    'type': 'validator-function-plain',
                                     'function': {'type': 'with-info', 'function': append_func},
                                 },
                             },
diff --git a/tests/benchmarks/test_micro_benchmarks.py b/tests/benchmarks/test_micro_benchmarks.py
index 2caa6fc83..dfdf8b322 100644
--- a/tests/benchmarks/test_micro_benchmarks.py
+++ b/tests/benchmarks/test_micro_benchmarks.py
@@ -966,7 +966,7 @@ def test_chain_list(benchmark):
 def test_chain_function(benchmark):
     validator = SchemaValidator(
         {
-            'type': 'function-after',
+            'type': 'validator-function-after',
             'schema': {'type': 'str'},
             'function': {'type': 'with-info', 'function': lambda v, info: Decimal(v)},
         }
@@ -997,9 +997,9 @@ def test_chain_two_functions(benchmark):
 def test_chain_nested_functions(benchmark):
     validator = SchemaValidator(
         {
-            'type': 'function-after',
+            'type': 'validator-function-after',
             'schema': {
-                'type': 'function-after',
+                'type': 'validator-function-after',
                 'schema': {'type': 'str'},
                 'function': {'type': 'with-info', 'function': lambda v, info: Decimal(v)},
             },
diff --git a/tests/test.rs b/tests/test.rs
index b59fbec54..92aada9ec 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -20,7 +20,7 @@ mod tests {
             //     },
             //     'ref': 'C-ref',
             //     'serialization': {
-            //         'type': 'function-wrap',
+            //         'type': 'serializer-function-wrap',
             //         'function': lambda: None,
             //     },
             let code = c_str!(
@@ -41,7 +41,7 @@ mod tests {
                         },
                         'ref': 'C-ref',
                         'serialization': {
-                            'type': 'function-wrap',
+                            'type': 'serializer-function-wrap',
                             'function': lambda: None,
                         },
                     },
diff --git a/tests/test_errors.py b/tests/test_errors.py
index 550f94e3d..b539e7678 100644
--- a/tests/test_errors.py
+++ b/tests/test_errors.py
@@ -93,7 +93,7 @@ def my_function(input_value, info):
         v.validate_python(42)
 
     assert str(exc_info.value) == (
-        '1 validation error for function-plain[my_function()]\n'
+        '1 validation error for validator-function-plain[my_function()]\n'
         "  (error rendering message: TypeError: 'tuple' object cannot be converted to 'PyString') "
         '[type=my_error, input_value=42, input_type=int]'
     )
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 806c4cca9..23318bae0 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -8,6 +8,7 @@
 from pydantic_core import CoreSchema, CoreSchemaType, PydanticUndefined, core_schema
 from pydantic_core._pydantic_core import (
     SchemaError,
+    SchemaSerializer,
     SchemaValidator,
     ValidationError,
     __version__,
@@ -214,3 +215,35 @@ def test_core_schema_import_field_validation_info():
 def test_core_schema_import_missing():
     with pytest.raises(AttributeError, match="module 'pydantic_core' has no attribute 'foobar'"):
         core_schema.foobar
+
+
+def test_deprecated_core_schema_types():
+    with pytest.warns(
+        DeprecationWarning, match="Core schema type 'function-plain' is deprecated, use 'validator-function-plain'"
+    ):
+        SchemaValidator(
+            {
+                'type': 'function-plain',
+                'function': {
+                    'type': 'no-info',
+                    'function': lambda v: v,
+                },
+            }
+        )
+
+    with pytest.warns(
+        DeprecationWarning,
+        match="Serialization core schema type 'function-plain' is deprecated, use 'serializer-function-plain'",
+    ):
+        SchemaSerializer(
+            {
+                'type': 'int',
+                'serialization': {
+                    'type': 'function-plain',
+                    'function': {
+                        'type': 'no-info',
+                        'function': lambda v: v,
+                    },
+                },
+            }
+        )
diff --git a/tests/test_schema_functions.py b/tests/test_schema_functions.py
index a15adfca5..bc5d489d7 100644
--- a/tests/test_schema_functions.py
+++ b/tests/test_schema_functions.py
@@ -112,7 +112,7 @@ def args(*args, **kwargs):
         core_schema.with_info_before_validator_function,
         args(val_function, {'type': 'int'}),
         {
-            'type': 'function-before',
+            'type': 'validator-function-before',
             'function': {'type': 'with-info', 'function': val_function},
             'schema': {'type': 'int'},
         },
@@ -121,7 +121,7 @@ def args(*args, **kwargs):
         core_schema.with_info_after_validator_function,
         args(val_function, {'type': 'int'}),
         {
-            'type': 'function-after',
+            'type': 'validator-function-after',
             'function': {'type': 'with-info', 'function': val_function},
             'schema': {'type': 'int'},
         },
@@ -130,7 +130,7 @@ def args(*args, **kwargs):
         core_schema.with_info_wrap_validator_function,
         args(val_function, {'type': 'int'}),
         {
-            'type': 'function-wrap',
+            'type': 'validator-function-wrap',
             'function': {'type': 'with-info', 'function': val_function},
             'schema': {'type': 'int'},
         },
@@ -310,7 +310,13 @@ def test_schema_functions(function, args_kwargs, expected_schema):
         pass
 
     # also build the serializer, just to check it doesn't raise an error
-    SchemaSerializer(schema)
+    if schema['type'] not in {
+        'validator-function-before',
+        'validator-function-after',
+        'validator-function-wrap',
+        'validator-function-plain',
+    }:
+        SchemaSerializer(schema)
 
 
 def test_all_schema_functions_used():
diff --git a/tests/test_typing.py b/tests/test_typing.py
index 2f460fb48..4a698dd5d 100644
--- a/tests/test_typing.py
+++ b/tests/test_typing.py
@@ -110,7 +110,7 @@ def test_schema_typing() -> None:
     }
     SchemaValidator(schema)
     schema: CoreSchema = {
-        'type': 'function-wrap',
+        'type': 'validator-function-wrap',
         'function': {'type': 'with-info', 'function': wrap_validator, 'field_name': 'foobar'},
         'schema': {'type': 'str'},
     }
diff --git a/tests/validators/test_chain.py b/tests/validators/test_chain.py
index 0ba59084d..ecceaab7f 100644
--- a/tests/validators/test_chain.py
+++ b/tests/validators/test_chain.py
@@ -82,11 +82,11 @@ def test_flatten():
                     'type': 'chain',
                     'steps': [
                         {
-                            'type': 'function-plain',
+                            'type': 'validator-function-plain',
                             'function': {'type': 'with-info', 'function': lambda v, info: f'{v}-2'},
                         },
                         {
-                            'type': 'function-plain',
+                            'type': 'validator-function-plain',
                             'function': {'type': 'with-info', 'function': lambda v, info: f'{v}-3'},
                         },
                     ],
@@ -96,7 +96,10 @@ def test_flatten():
     )
 
     assert validator.validate_python('input') == 'input-1-2-3'
-    assert validator.title == 'chain[function-plain[<lambda>()],function-plain[<lambda>()],function-plain[<lambda>()]]'
+    assert (
+        validator.title
+        == 'chain[validator-function-plain[<lambda>()],validator-function-plain[<lambda>()],validator-function-plain[<lambda>()]]'
+    )
 
 
 def test_chain_empty():
@@ -109,4 +112,4 @@ def test_chain_one():
         {'type': 'chain', 'steps': [core_schema.with_info_plain_validator_function(lambda v, info: f'{v}-1')]}
     )
     assert validator.validate_python('input') == 'input-1'
-    assert validator.title == 'function-plain[<lambda>()]'
+    assert validator.title == 'validator-function-plain[<lambda>()]'
diff --git a/tests/validators/test_definitions_recursive.py b/tests/validators/test_definitions_recursive.py
index e835b9075..0fb5e75a8 100644
--- a/tests/validators/test_definitions_recursive.py
+++ b/tests/validators/test_definitions_recursive.py
@@ -673,7 +673,7 @@ def f(input_value, info):
     assert exc_info.value.errors(include_url=False) == [
         {
             'type': 'recursion_loop',
-            'loc': ('function-after[f(), ...]',),
+            'loc': ('validator-function-after[f(), ...]',),
             'msg': 'Recursion error - cyclic reference detected',
             'input': 'input value',
         },
diff --git a/tests/validators/test_function.py b/tests/validators/test_function.py
index 544bf416d..39708274d 100644
--- a/tests/validators/test_function.py
+++ b/tests/validators/test_function.py
@@ -65,7 +65,7 @@ def my_function(input_value, info):
 
     v = SchemaValidator(
         {
-            'type': 'function-before',
+            'type': 'validator-function-before',
             'function': {'type': 'with-info', 'function': my_function},
             'schema': {'type': 'str', 'max_length': 5},
         }
@@ -83,7 +83,9 @@ def my_function(input_value, info):
             'ctx': {'max_length': 5},
         }
     ]
-    assert repr(exc_info.value).startswith('1 validation error for function-before[my_function(), constrained-str]\n')
+    assert repr(exc_info.value).startswith(
+        '1 validation error for validator-function-before[my_function(), constrained-str]\n'
+    )
 
 
 @pytest.mark.parametrize(
@@ -100,7 +102,7 @@ def my_function(input_value, info):
 
     v = SchemaValidator(
         {
-            'type': 'function-before',
+            'type': 'validator-function-before',
             'function': {'type': 'with-info', 'function': my_function},
             'schema': {'type': 'str', 'max_length': 5},
         },
@@ -119,7 +121,7 @@ def f(input_value, info):
 
     v = SchemaValidator(
         {
-            'type': 'function-before',
+            'type': 'validator-function-before',
             'function': {'type': 'with-info', 'function': f},
             'schema': {
                 'type': 'typed-dict',
@@ -206,11 +208,13 @@ def f(input_value, validator, info):
 
 
 def test_function_wrap_not_callable():
-    with pytest.raises(SchemaError, match='function-wrap.function.typed-dict.function\n  Input should be callable'):
+    with pytest.raises(
+        SchemaError, match='validator-function-wrap.function.typed-dict.function\n  Input should be callable'
+    ):
         validate_core_schema(core_schema.with_info_wrap_validator_function([], core_schema.str_schema()))
 
-    with pytest.raises(SchemaError, match='function-wrap.function\n  Field required'):
-        validate_core_schema({'type': 'function-wrap', 'schema': {'type': 'str'}})
+    with pytest.raises(SchemaError, match='validator-function-wrap.function\n  Field required'):
+        validate_core_schema({'type': 'validator-function-wrap', 'schema': {'type': 'str'}})
 
 
 def test_wrap_error():
@@ -375,7 +379,7 @@ def f(input_value, info):
                 'test_field': {
                     'type': 'typed-dict-field',
                     'schema': {
-                        'type': 'function-after',
+                        'type': 'validator-function-after',
                         'function': {'type': 'with-info', 'function': f, 'field_name': 'test_field'},
                         'schema': {'type': 'str'},
                     },
@@ -424,10 +428,10 @@ def f(input_value):
 
 
 def test_plain_with_schema():
-    with pytest.raises(SchemaError, match='function-plain.schema\n  Extra inputs are not permitted'):
+    with pytest.raises(SchemaError, match='validator-function-plain.schema\n  Extra inputs are not permitted'):
         validate_core_schema(
             {
-                'type': 'function-plain',
+                'type': 'validator-function-plain',
                 'function': {'type': 'with-info', 'function': lambda x: x},
                 'schema': {'type': 'str'},
             }
@@ -497,7 +501,7 @@ def __validate__(cls, input_value, info):
 
     v = SchemaValidator(
         {
-            'type': 'function-after',
+            'type': 'validator-function-after',
             'function': {'type': 'with-info', 'function': Foobar.__validate__},
             'schema': {'type': 'str'},
         }
diff --git a/tests/validators/test_model.py b/tests/validators/test_model.py
index 1d6ab7f47..1006299dc 100644
--- a/tests/validators/test_model.py
+++ b/tests/validators/test_model.py
@@ -451,7 +451,7 @@ def f(input_value, info):
             'type': 'model',
             'cls': MyModel,
             'schema': {
-                'type': 'function-after',
+                'type': 'validator-function-after',
                 'function': {'type': 'with-info', 'function': f},
                 'schema': {
                     'type': 'model-fields',
diff --git a/tests/validators/test_model_fields.py b/tests/validators/test_model_fields.py
index 491a3baf8..3e7fa8631 100644
--- a/tests/validators/test_model_fields.py
+++ b/tests/validators/test_model_fields.py
@@ -280,7 +280,7 @@ def func_b(input_value, info):
                 'field_a': {
                     'type': 'model-field',
                     'schema': {
-                        'type': 'function-after',
+                        'type': 'validator-function-after',
                         'function': {'type': 'with-info', 'function': func_a},
                         'schema': {'type': 'str'},
                     },
@@ -288,7 +288,7 @@ def func_b(input_value, info):
                 'field_b': {
                     'type': 'model-field',
                     'schema': {
-                        'type': 'function-after',
+                        'type': 'validator-function-after',
                         'function': {'type': 'with-info', 'function': func_b},
                         'schema': {'type': 'int'},
                     },
@@ -1608,7 +1608,7 @@ def wrap_function(input_value, validator, info):
                             'type': 'default',
                             'on_error': 'raise',
                             'schema': {
-                                'type': 'function-wrap',
+                                'type': 'validator-function-wrap',
                                 'function': {'type': 'with-info', 'function': wrap_function},
                                 'schema': {'type': 'str'},
                             },
diff --git a/tests/validators/test_model_init.py b/tests/validators/test_model_init.py
index f1226265a..7f8647d78 100644
--- a/tests/validators/test_model_init.py
+++ b/tests/validators/test_model_init.py
@@ -100,7 +100,7 @@ def f(input_value, _info):
 
     v = SchemaValidator(
         {
-            'type': 'function-before',
+            'type': 'validator-function-before',
             'function': {'type': 'with-info', 'function': f},
             'schema': {
                 'type': 'model',
@@ -136,7 +136,7 @@ def f(input_value, _info):
 
     v = SchemaValidator(
         {
-            'type': 'function-after',
+            'type': 'validator-function-after',
             'function': {'type': 'with-info', 'function': f},
             'schema': {
                 'type': 'model',
@@ -174,7 +174,7 @@ def f(input_value, handler, _info):
 
     v = SchemaValidator(
         {
-            'type': 'function-wrap',
+            'type': 'validator-function-wrap',
             'function': {'type': 'with-info', 'function': f},
             'schema': {
                 'type': 'model',
diff --git a/tests/validators/test_typed_dict.py b/tests/validators/test_typed_dict.py
index b41a1188f..0182f0b90 100644
--- a/tests/validators/test_typed_dict.py
+++ b/tests/validators/test_typed_dict.py
@@ -1065,7 +1065,7 @@ def wrap_function(input_value, validator, info):
                             'type': 'default',
                             'on_error': 'raise',
                             'schema': {
-                                'type': 'function-wrap',
+                                'type': 'validator-function-wrap',
                                 'function': {'type': 'with-info', 'function': wrap_function},
                                 'schema': {'type': 'str'},
                             },