from marshmallow import Schema, fields, pprint


class InnerSchema(Schema):
    value = fields.Function(lambda val, ctx: 'foo' in ctx['from_outer'])


class OuterSchema(Schema):
    inner = fields.Nested(InnerSchema)
schema = OuterSchema(context={'from_outer': 'foo'})
obj = {'inner': {}}
result = schema.dump(obj)
pprint(result.data)
How to pass context to nested serializers in Marshmallow?