Waveguide characterization of dielectric materials is a convenient and broadband approach for measuring dielectric constant. In conventional microwave measurements, material samples are usually mechanically shaped to fit the waveguide opening and measured in closed waveguides. This method is not practical for millimeter-wave and sub-millimeter-wave measurements where the waveguide openings become tiny, and it is rather difficult to shape the sample to exactly the same dimensions as the waveguide cross-section. In this paper, we present a method that allows one to measure arbitrarily shaped dielectric slabs that extend outside waveguides. In this method, the measured sample is placed between two waveguide flanges, creating a discontinuity. The measurement system is characterized as an equivalent Pi-circuit, and the circuit elements of the Pi-circuit are extracted from the scattering parameters. We have found that the equivalent shunt impedance of the measured sample is only determined by the material permittivity and is rather insensitive to the sample shape, position, sizes, and other structural details of the discontinuity. This feature can be leveraged for accurate measurements of permittivity. The proposed method is very useful for measuring the permittivity of medium-loss and high-loss dielectrics from microwave to sub-terahertz frequencies.